# fm v1.9.1 by Kiah Morante # A very simple file manager. # Depends on pycp/pymv, http://github.com/yannicklm/pycp and feh # 'source' this file in a BASH shell source ~/.bashrc showHidden=0 # Hidden files not shown showDetails=0 # ls is replaced with ls -lh if showDetails is 1 shopt -s autocd # cd to a dir just by typing its name PROMPT_COMMAND='[[ ${__new_wd:=$PWD} != $PWD ]] && list; __new_wd=$PWD' # ls after cding # Shortcuts source ~/.config/fm/shortcuts # Call all custom shortcuts alias ..='cd ..' alias ...='cd ../..' alias ....='cd ../../..' alias h='cd ~' alias n='cd "$n"' # Keybindings bind '"\C-l":"list\C-m"' bind '"\C-h":"hide\C-m"' bind '"\C-o":"details\C-m"' bind '"\C-f":"makedir\C-m"' bind '"\C-n":"n\C-m"' bind '"\C-y":"cpwd\C-m"' bind '"\C-p":"cd "$OLDPWD"\C-m"' # Hint: You could also type '~-' # FM prompt appearance if [[ $(whoami) == 'root' ]]; then # So that the user knows if they have root privileges: PS1="\[\e[0;32\]mf\[m\e[m\] \[\e[0;31m\]root\[\e[m\] \A \[\e[0;34m\]\w \[\e[m\]\[\e[0;31m\]> \[\e[m\]" else PS1="\[\e[0;32\]mf\[m\e[m\] \A \[\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. lsd - list directories cd - changed to directory \$1 cp \$@ \$2 - copies file from \$1 to \$2 mv \$@ \$2 - moves file from \$1 to \$2 rm \$@ - deletes \$@ sc \$1 \$2 - make a shortcut called \$1 pointing to \$2. If no \$2 is passed, it is evaluated as \$PWD cpwd - copy current working directory .., ..., .... - cd .. etc. o \$1 - opens \$1 with xdg-open hm - how many files are in the current directory details - show file details (ls -lh) fmhelp - this help menu n - Intelligent guess of the next dir you wish to cd to. Last $1 in open, list, or makedir; last argument in copy or move; pwd before a cd ~- - BASH shortcut for \$OLDPWD img - feh frontend with the following usage: img -t \$2 - views the dirs/images specified in \$2..\$n as clickable thumbnails img -s \$2 \$3 - views the images specified in \$3..\$n as a slideshow with a slide change speed of \$2 seconds img \$@ - views the dirs/images specified Shortkeys: Ctrl-f - mkdir Ctrl-h - hide Ctrl-l - ls Ctrl-n - cd \$n Ctrl-o - details Ctrl-p - cd \$OLDPWD Ctrl-y - cpwd Ctrl-u - clear line (urxvt default)" } # 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, file details are shown details () { showDetails=$(( 1 - $showDetails )) list } # ls listToggle () { if [[ $showHidden == 1 && $showDetails == 1 ]]; then ls -C --color -A -lh "$dir" elif [[ $showHidden == 1 && $showDetails == 0 ]]; then ls -C --color -A "$dir" elif [[ $showHidden == 0 && $showDetails == 1 ]]; then ls -C --color -lh "$dir" else ls -C --color "$dir" fi } list () { clear # Unclutter the screen # List pwd if no $1 if [[ $@ == "" ]]; then set '.' fi # List multiple folders: for dir in "$@" do listToggle done n="$1" # See 'n' in fmhelp } # use feh to view thumbnails/images/slideshow img () { case "$1" in -t) nohup feh -. --thumbnails "${@:2}" --thumb-height 120 --thumb-width 120 -S filename -d --cache-thumbnails -B black > /dev/null 2>&1 & ;; -s) nohup feh "${@:3}" -. -S filename -d -B black --slideshow-delay "$2" > /dev/null 2>&1 & ;; *) nohup feh "$@" -. -S filename -d -B black > /dev/null 2>&1 & ;; esac list } # cp copy () { if [[ $showHidden == 1 ]]; then pycp --interactive --all "$@" else pycp --interactive "$@" fi list n="${@:(-1)}" # n is the last argument (where stuff is moved to) } # mv move () { if [[ $showHidden == 1 ]]; then pymv --interactive --all "$@" else pymv --interactive "$@" fi list n="${@:(-1)}" } makedir () { if [[ $1 == "" ]]; then read -e n set "$n" fi if mkdir -- "$1"; then list # Update pwd to show new dir(s) that have been made. n="$1" fi } # rm remove () { rm -rfI "$@" list } # open files o () { # To use xdg-open #nohup xdg-open "$1" > /dev/null 2>&1 & if [ -f "$1" ] ; then case "$1" in *.tar.bz2) tar xjf "$1" ;; *.tar.gz) tar xzf "$1" ;; *.bz2) bunzip2 "$1" ;; *.rar) rar x "$1" ;; *.gz) gunzip "$1" ;; *.tar) tar xf "$1" ;; *.tbz2) tar xjf "$1" ;; *.tgz) tar xzf "$1" ;; *.zip) unzip "$1" ;; *.Z) uncompress "$1" ;; *.7z) 7z x "$1" ;; *.pdf) nohup apvlv "$1" > /dev/null 2>&1 & ;; *.djvu) nohup apvlv "$1" > /dev/null 2>&1 & ;; *.html) nohup luakit "$1" > /dev/null 2>&1 & ;; *.blend) nohup blender "$1" > /dev/null 2>&1 & ;; *.avi) nohup mplayer "$1" > /dev/null 2>&1 & ;; *.wmv) nohup mplayer "$1" > /dev/null 2>&1 & ;; *.rmvb) nohup mplayer "$1" > /dev/null 2>&1 & ;; *.mkv) nohup mplayer "$1" > /dev/null 2>&1 & ;; *.mp3) nohup urxvtc -si -sw -sh 30 -e mplayer "$1" > /dev/null 2>&1 & ;; *.flv) nohup mplayer "$1" ;; *.mp4) nohup mplayer "$1" ;; *.ogg) nohup urxvtc -si -sw -sh 30 -e mplayer "$1" > /dev/null 2>&1 & ;; *.wav) nohup audacity "$1" > /dev/null 2>&1 & ;; *.jpg) img "$1" ;; *.jpeg) img "$1" ;; *.JPG) img "$1" ;; *.png) img "$1" ;; *.gif) nohup gpicview "$1" > /dev/null 2>&1 & ;; *.pnm) nohup gpicview "$1" > /dev/null 2>&1 & ;; *) nohup urxvtc -si -sw -sh 30 -e vim "$1" > /dev/null 2>&1 & ;; esac else echo "'$1' is not a valid file" fi n="$1" } # Add shortcuts makeShortcut () { if [[ $2 == "" ]]; then set $1 . fi echo ""$1"=\""$2"\" alias "$1"='cd \""$2"\"' " >> ~/.config/fm/shortcuts source ~/.config/fm/shortcuts } # Copy pwd to clipboard cpwd () { echo \"$(pwd)\" | xclip } # List directories lsd () { ls -F "$@" | grep \/$ } # Command aliases alias mv="move" alias sc="makeShortcut" alias cp="copy" alias ls="list" alias rm="remove" alias mkdir="makedir" alias hm="ls -l . | egrep -c '^-'" list # ls when fm starts