Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # fm v1.2 by Kiah Morante
- # A very simple file manager.
- # Depends on pycp/pymv, http://github.com/yannicklm/pycp
- # 'source' this file in a BASH shell
- showHidden=0 # Hidden files not shown
- showDetails=0 # ls is replaced with ls -l if showDetails is 1
- # So that the user knows if they have root privileges:
- if [[ $(whoami) == 'root' ]]; then
- PS1="\[\e[0;32\]mf\[m\e[m\] \[\e[0;31m\]root\[\e[m\] \[\e[0;34m\]\w \[\e[m\]\[\e[0;31m\]> \[\e[m\]"
- else
- PS1="\[\e[0;32\]mf\[m\e[m\] \[\e[0;34m\]\w \[\e[m\]\[\e[0;31m\]> \[\e[m\]"
- fi
- # Functions
- # Usage
- fmhelp () {
- echo "hide - toggle hidden (hidden by default)
- ls - lists contents of dir(s) passed in args.
- cd - changed to directory $1
- cp $1 $2 - copies file from $1 to $2
- mv $1 $2 - moves file from $1 to $2
- .., ..., .... - cd .. etc.
- o $1 - opens $1 with xdg-open
- details - show file details (ls -l)
- Shortkeys:
- Ctrl-g - cd
- Ctrl-h - this help menu
- Ctrl-H - hide
- Ctrl-l - ls"
- }
- # cd
- changedir () {
- if [[ $1 == "" ]]; then
- read -re goto
- set "$goto"
- fi
- if cd $1; then
- list
- fi
- }
- # Toggle display hidden files
- # If $showHidden is 1, hidden files are shown
- hide () {
- showHidden=$(( 1 - $showHidden ))
- list
- }
- # Toggle display file details
- # If $showDetails is 1, hidden files are shown
- details () {
- showDetails=$(( 1 - $showDetails ))
- list
- }
- # ls
- listToggle () {
- if [[ $showHidden == 1 && $showDetails == 1 ]]; then
- ls -C --color -A -l "$dir"
- elif [[ $showHidden == 1 && $showDetails == 0 ]]; then
- ls -C --color -A "$dir"
- elif [[ $showHidden == 0 && $showDetails == 1 ]]; then
- ls -C --color -l "$dir"
- else
- ls -C --color "$dir"
- fi
- }
- list () {
- clear
- # List pwd if no $1
- if [[ $@ == "" ]]; then
- set '.'
- fi
- # List multiple folders:
- for dir in "$@"
- do
- listToggle
- done
- }
- # cp
- copy () {
- if [[ $showHidden == 1 ]]; then
- pycp --interactive --all "$@"
- else
- pycp --interactive "$@"
- fi
- }
- # mv
- move () {
- if [[ $showHidden == 1 ]]; then
- pymv --interactive --all "$@"
- else
- pymv --interactive "$@"
- fi
- }
- # open files
- o () {
- nohup xdg-open "$1" > /dev/null 2>&1 &
- }
- # Command aliases
- alias mv="move"
- alias cp="copy"
- alias ls="list"
- alias cd="changedir"
- alias rm="rm -rfI"
- # Shortcuts
- # Do NOT name one 'i'
- alias ..='changedir ..'
- alias ...='changedir ../..'
- alias ....='changedir ../../..'
- z="/media/disk/"
- alias z="changedir $z"
- x="/media/sdb4/"
- alias x="changedir $x"
- alias h="changedir ~"
- # Keybindings:
- bind '"\C-g":"changedir\C-m"'
- bind '"\C-l":"list\C-m"'
- bind '"\C-H":"hide\C-m"'
- bind '"\C-h":"fmhelp\C-m"'
Advertisement
Add Comment
Please, Sign In to add comment