Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Jul 13th, 2011  |  syntax: Bash  |  size: 6.81 KB  |  views: 137  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. # fm v1.9.1 by Kiah Morante
  2. # A very simple file manager.
  3. # Depends on pycp/pymv, http://github.com/yannicklm/pycp and feh
  4. # 'source' this file in a BASH shell
  5.  
  6. source ~/.bashrc
  7.  
  8. showHidden=0 # Hidden files not shown
  9. showDetails=0 # ls is replaced with ls -lh if showDetails is 1
  10.  
  11. shopt -s autocd # cd to a dir just by typing its name
  12. PROMPT_COMMAND='[[ ${__new_wd:=$PWD} != $PWD ]] && list; __new_wd=$PWD' # ls after cding
  13.  
  14. # Shortcuts
  15. source ~/.config/fm/shortcuts # Call all custom shortcuts
  16.  
  17. alias ..='cd ..'
  18. alias ...='cd ../..'
  19. alias ....='cd ../../..'
  20. alias h='cd ~'
  21. alias n='cd "$n"'
  22.  
  23. # Keybindings
  24.  
  25. bind '"\C-l":"list\C-m"'
  26. bind '"\C-h":"hide\C-m"'
  27. bind '"\C-o":"details\C-m"'
  28. bind '"\C-f":"makedir\C-m"'
  29. bind '"\C-n":"n\C-m"'
  30. bind '"\C-y":"cpwd\C-m"'
  31. bind '"\C-p":"cd "$OLDPWD"\C-m"' # Hint: You could also type '~-'
  32.  
  33. # FM prompt appearance
  34.  
  35. if [[ $(whoami) == 'root' ]]; then
  36.     # So that the user knows if they have root privileges:
  37.     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\]"
  38. else
  39.     PS1="\[\e[0;32\]mf\[m\e[m\] \A \[\e[0;34m\]\w \[\e[m\]\[\e[0;31m\]> \[\e[m\]"
  40. fi
  41.  
  42. # Functions
  43.  
  44. # Usage
  45. fmhelp () {
  46.     echo "hide - toggle hidden (hidden by default)
  47. ls - lists contents of dir(s) passed in args.
  48. lsd - list directories
  49. cd - changed to directory \$1
  50. cp \$@ \$2 - copies file from \$1 to \$2
  51. mv \$@ \$2 - moves file from \$1 to \$2
  52. rm \$@ - deletes \$@
  53. sc \$1 \$2 - make a shortcut called \$1 pointing to \$2. If no \$2 is passed, it is evaluated as \$PWD
  54. cpwd - copy current working directory
  55. .., ..., .... - cd .. etc.
  56. o \$1 - opens \$1 with xdg-open
  57. hm - how many files are in the current directory
  58. details - show file details (ls -lh)
  59. fmhelp - this help menu
  60. 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
  61. ~- - BASH shortcut for \$OLDPWD
  62.  
  63. img - feh frontend with the following usage:
  64.      img -t \$2 - views the dirs/images specified in \$2..\$n as clickable thumbnails
  65.      img -s \$2 \$3 - views the images specified in \$3..\$n as a slideshow with a slide change speed of \$2 seconds
  66.      img \$@ - views the dirs/images specified
  67.  
  68. Shortkeys:
  69.  
  70. Ctrl-f - mkdir
  71. Ctrl-h - hide
  72. Ctrl-l - ls
  73. Ctrl-n - cd \$n
  74. Ctrl-o - details
  75. Ctrl-p - cd \$OLDPWD
  76. Ctrl-y - cpwd
  77. Ctrl-u - clear line (urxvt default)"
  78. }
  79.  
  80. # Toggle display hidden files
  81. # If $showHidden is 1, hidden files are shown
  82. hide () {
  83.     showHidden=$(( 1 - $showHidden ))
  84.     list
  85. }
  86.  
  87. # Toggle display file details
  88. # If $showDetails is 1, file details are shown
  89. details () {
  90.     showDetails=$(( 1 - $showDetails ))
  91.     list
  92. }
  93.  
  94.  
  95. # ls
  96. listToggle () {
  97.     if [[ $showHidden == 1 && $showDetails == 1 ]]; then
  98.         ls -C --color -A -lh "$dir"
  99.     elif [[ $showHidden == 1 && $showDetails == 0 ]]; then
  100.         ls -C --color -A "$dir"
  101.     elif [[ $showHidden == 0 && $showDetails == 1 ]]; then
  102.         ls -C --color -lh "$dir"
  103.     else
  104.         ls -C --color "$dir"
  105.     fi
  106. }
  107.  
  108. list () {
  109.     clear # Unclutter the screen
  110.    
  111.     # List pwd if no $1
  112.     if [[ $@ == "" ]]; then
  113.         set '.'
  114.     fi
  115.  
  116.     # List multiple folders:
  117.     for dir in "$@"
  118.     do
  119.         listToggle
  120.     done
  121.  
  122.     n="$1" # See 'n' in fmhelp
  123. }
  124.  
  125. # use feh to view thumbnails/images/slideshow
  126.  
  127. img () {
  128.  
  129.     case "$1" in
  130.        -t)       nohup feh -. --thumbnails "${@:2}" --thumb-height 120 --thumb-width 120 -S filename -d --cache-thumbnails -B black > /dev/null 2>&1 & ;;
  131.        -s)       nohup feh "${@:3}" -. -S filename -d -B black --slideshow-delay "$2" > /dev/null 2>&1 & ;;
  132.        *)        nohup feh "$@" -. -S filename -d -B black > /dev/null 2>&1 & ;;
  133.     esac
  134.  
  135.     list
  136. }
  137.  
  138. # cp
  139. copy () {
  140.     if [[ $showHidden == 1 ]]; then
  141.         pycp --interactive --all "$@"
  142.     else
  143.         pycp --interactive "$@"
  144.     fi
  145.  
  146.     list
  147.     n="${@:(-1)}" # n is the last argument (where stuff is moved to)
  148. }
  149.  
  150. # mv
  151. move () {
  152.     if [[ $showHidden == 1 ]]; then
  153.         pymv --interactive --all "$@"
  154.     else
  155.         pymv --interactive "$@"
  156.     fi
  157.  
  158.     list
  159.     n="${@:(-1)}"
  160. }
  161.  
  162. makedir () {
  163.      if [[ $1 == "" ]]; then
  164.          read -e n
  165.          set "$n"
  166.      fi
  167.  
  168.      if mkdir -- "$1"; then
  169.          list # Update pwd to show new dir(s) that have been made.
  170.          n="$1"
  171.      fi
  172. }
  173.  
  174. # rm
  175. remove () {
  176.      rm -rfI "$@"
  177.      list
  178. }
  179.  
  180. # open files
  181. o () {
  182.     # To use xdg-open
  183.     #nohup xdg-open "$1" > /dev/null 2>&1 &
  184.  
  185.     if [ -f "$1" ] ; then
  186.        case "$1" in
  187.        *.tar.bz2)   tar xjf "$1"    ;;
  188.        *.tar.gz)    tar xzf "$1"    ;;
  189.        *.bz2)       bunzip2 "$1"    ;;
  190.        *.rar)       rar x "$1"      ;;
  191.        *.gz)        gunzip "$1"     ;;
  192.        *.tar)       tar xf "$1"     ;;
  193.        *.tbz2)      tar xjf "$1"    ;;
  194.        *.tgz)       tar xzf "$1"    ;;
  195.        *.zip)       unzip "$1"      ;;
  196.        *.Z)         uncompress "$1" ;;
  197.        *.7z)        7z x "$1"       ;;
  198.        *.pdf)       nohup apvlv "$1" > /dev/null 2>&1 &     ;;
  199.        *.djvu)      nohup apvlv "$1" > /dev/null 2>&1 &     ;;
  200.        *.html)      nohup luakit "$1" > /dev/null 2>&1 &      ;;
  201.        *.blend)     nohup blender "$1" > /dev/null 2>&1 &     ;;
  202.        *.avi)       nohup mplayer "$1" > /dev/null 2>&1 &  ;;
  203.        *.wmv)       nohup mplayer "$1" > /dev/null 2>&1 & ;;
  204.        *.rmvb)      nohup mplayer "$1" > /dev/null 2>&1 & ;;
  205.        *.mkv)       nohup mplayer "$1" > /dev/null 2>&1 & ;;
  206.        *.mp3)       nohup urxvtc -si -sw -sh 30 -e mplayer "$1" > /dev/null 2>&1 &     ;;
  207.        *.flv)       nohup mplayer "$1"  ;;
  208.        *.mp4)       nohup mplayer "$1"  ;;
  209.        *.ogg)       nohup urxvtc -si -sw -sh 30 -e mplayer "$1" > /dev/null 2>&1 &      ;;
  210.        *.wav)       nohup audacity "$1" > /dev/null 2>&1 &    ;;
  211.        *.jpg)       img "$1"        ;;
  212.        *.jpeg)      img "$1"        ;;
  213.        *.JPG)       img "$1"        ;;
  214.        *.png)       img "$1"        ;;
  215.        *.gif)       nohup gpicview "$1" > /dev/null 2>&1 &    ;;
  216.        *.pnm)       nohup gpicview "$1" > /dev/null 2>&1 &    ;;
  217.        *)           nohup urxvtc -si -sw -sh 30 -e vim "$1" > /dev/null 2>&1 &          ;;
  218.        esac
  219.     else
  220.         echo "'$1' is not a valid file"
  221.     fi
  222.  
  223.     n="$1"
  224. }
  225.  
  226. # Add shortcuts
  227.  
  228. makeShortcut () {
  229.     if [[ $2 == "" ]]; then
  230.         set $1 .
  231.     fi
  232.  
  233.     echo ""$1"=\""$2"\"
  234.    alias "$1"='cd \""$2"\"'
  235.         " >> ~/.config/fm/shortcuts
  236.  
  237.     source ~/.config/fm/shortcuts
  238. }
  239.  
  240. # Copy pwd to clipboard
  241.  
  242. cpwd () {
  243.     echo \"$(pwd)\" | xclip
  244. }
  245.  
  246. # List directories
  247.  
  248. lsd () {
  249.     ls -F "$@" | grep \/$
  250. }
  251.  
  252. # Command aliases
  253.  
  254. alias mv="move"
  255. alias sc="makeShortcut"
  256. alias cp="copy"
  257. alias ls="list"
  258. alias rm="remove"
  259. alias mkdir="makedir"
  260. alias hm="ls -l . | egrep -c '^-'"
  261.  
  262. list # ls when fm starts