-
-
Notifications
You must be signed in to change notification settings - Fork 0
files manager
Yeah, maybe you don't...
A machine without a files manager is too minimal!
Of course everyone have their own different need and workflow. But if you have an satifice shell config and want to utilize it as much as possible. Then maybe you don't need a files manage and instead, you should use your terminal for files managing. This guide will not only teach you how to managing files but also do it optimally.
Here is all of files managers uses that I could think of:
For the sake of convenience, I will call files and directories as items.
- Enter a directory location.
- See a directory's content.
- Drag and drop items to different applications.
- Searching for items.
- Create new items.
- Copy, cut, link, delete and rename items.
- Extract and archive items.
- Check free and used spaces.
- Open terminal in current directory.
Those are all things that the terminal can easily do:
To enter a directory, type cd path/to/dir
. But if your shell support implicit directory change, enable it if it isn't already so you can enter a path just by typing it out.
You could also utilize it with a fuzzy picker (example).
Use ls
or other alternatives. Alias it in your shell as l
for easy access.
You could alias cd
and ls
to the same command to quickly view a directory's contents. But if your shell have a hook/event system, it's best to set it automatically ls
every time you change your directory. Here is an example for Xonsh:
@events.on_chdir
def auto_ls(olddir, newdir, **kw):
ls
Most programs and web apps already have a button to open a file picker, but if you really want it, check out Dragon.
Use find
or other alternatives. Then you could also utilize it with a fuzzy picker. Alias it in your shell as f
for easy access.
To create a new directory, type mkdir -p dir_name
. Alias it in your shell as mk
, mkd
or md
for easy access.
To create a new file, type touch file_name
or just open it with a text editor, it will automatically be created when you save the file.
- To copy items, use
cp -r
. - To cut and rename, use
mv
(rename file bymv file_with_old_name file_with_new_name
). - To link items, use
ln -s
. - To delete items, use
rm -rf
or trash-cli.
If you want to select some items, cd
to a new path, then copy/cut/link items to current directory. Add this to your shell config:
For Bash/Zsh
s() {
SELECTION=()
for item in "$@"; do
SELECTION+=("$(readlink -f "$item")")
done
}
mv() { if [ "$#" -eq '0' ]; then command mv "${SELECTION[@]}" .; else command mv "$@"; fi }
cp() { if [ "$#" -eq '0' ]; then command cp -r "${SELECTION[@]}" .; else command cp -r "$@"; fi }
ln() { if [ "$#" -eq '0' ]; then command ln -s "${SELECTION[@]}" .; else command ln -s "$@"; fi }
hln() { if [ "$#" -eq '0' ]; then command ln "${SELECTION[@]}" .; else command ln "$@"; fi }
For Xonsh
import os
$SELECTION = None
def set_file_select(items):
$SELECTION = [os.path.abspath(item) for item in items]
aliases["s"] = lambda args: set_file_select(args)
aliases["mv"] = lambda args: execx("mv @($SELECTION) .") if not args else execx(" ".join(["mv"] + args))
aliases["cp"] = lambda args: execx("cp -r @($SELECTION) .") if not args else execx(" ".join(["cp -r"] + args))
aliases["ln"] = lambda args: execx("ln -s @($SELECTION) .") if not args else execx(" ".join(["ln -s"] + args))
aliases["hln"] = lambda args: execx("ln @($SELECTION) .") if not args else execx(" ".join(["ln"] + args))
Now you can mark items as selected by s item1 item2 ...
, cd
to a new path then simply type cp
, mv
or ln
with no arguments, it will do the jobs. Of course you can still use those commands normally.
Some more ideas:
- Clipboard: Set string of items to clipboard when selected to use in other terminal or GUI apps.
- Register: you can operate in any specific register (also cross shell).
- Smart cut: after cutting the file to a new path, the file's new path will be automatically copied for future operation.
Also check out edir
if you want to bulk rename, delete and copy items.
Use Patool or other archiving and compression tools. Alias it in your shell for easy access.
Use du
or other disk usage display tools. If you want this to always visible, add it to your prompt.
You already in a terminal...
Special thanks to:
- Kazoku for help me with the selection config for Bash/Zsh.