Guest User

Untitled

a guest
Sep 20th, 2010
608
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.77 KB | None | 0 0
  1. # fm v1.2 by Kiah Morante
  2. # A very simple file manager.
  3. # Depends on pycp/pymv, http://github.com/yannicklm/pycp
  4. # 'source' this file in a BASH shell
  5.  
  6. showHidden=0 # Hidden files not shown
  7. showDetails=0 # ls is replaced with ls -l if showDetails is 1
  8.  
  9. # So that the user knows if they have root privileges:
  10.  
  11. if [[ $(whoami) == 'root' ]]; then
  12.     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\]"
  13. else
  14.     PS1="\[\e[0;32\]mf\[m\e[m\] \[\e[0;34m\]\w \[\e[m\]\[\e[0;31m\]> \[\e[m\]"
  15. fi
  16.  
  17. # Functions
  18.  
  19. # Usage
  20. fmhelp () {
  21.     echo "hide - toggle hidden (hidden by default)
  22. ls - lists contents of dir(s) passed in args.
  23. cd - changed to directory $1
  24. cp $1 $2 - copies file from $1 to $2
  25. mv $1 $2 - moves file from $1 to $2
  26. .., ..., .... - cd .. etc.
  27. o $1 - opens $1 with xdg-open
  28. details - show file details (ls -l)
  29.  
  30. Shortkeys:
  31. Ctrl-g - cd
  32. Ctrl-h - this help menu
  33. Ctrl-H - hide
  34. Ctrl-l - ls"
  35. }
  36.  
  37. # cd
  38. changedir () {
  39.      if [[ $1 == "" ]]; then
  40.          read -re goto
  41.          set "$goto"
  42.      fi
  43.  
  44.      if cd $1; then
  45.          list
  46.      fi
  47. }
  48.  
  49. # Toggle display hidden files
  50. # If $showHidden is 1, hidden files are shown
  51. hide () {
  52.     showHidden=$(( 1 - $showHidden ))
  53.     list
  54. }
  55.  
  56. # Toggle display file details
  57. # If $showDetails is 1, hidden files are shown
  58. details () {
  59.     showDetails=$(( 1 - $showDetails ))
  60.     list
  61. }
  62.  
  63.  
  64. # ls
  65. listToggle () {
  66.     if [[ $showHidden == 1 && $showDetails == 1 ]]; then
  67.         ls -C --color -A -l "$dir"
  68.     elif [[ $showHidden == 1 && $showDetails == 0 ]]; then
  69.         ls -C --color -A "$dir"
  70.     elif [[ $showHidden == 0 && $showDetails == 1 ]]; then
  71.         ls -C --color -l "$dir"
  72.     else
  73.         ls -C --color "$dir"
  74.     fi
  75. }
  76.  
  77. list () {
  78.     clear
  79.    
  80.     # List pwd if no $1
  81.     if [[ $@ == "" ]]; then
  82.         set '.'
  83.     fi
  84.  
  85.     # List multiple folders:
  86.     for dir in "$@"
  87.     do
  88.         listToggle
  89.     done
  90. }
  91.  
  92. # cp
  93. copy () {
  94.     if [[ $showHidden == 1 ]]; then
  95.         pycp --interactive --all "$@"
  96.     else
  97.         pycp --interactive "$@"
  98.     fi
  99. }
  100.  
  101. # mv
  102. move () {
  103.     if [[ $showHidden == 1 ]]; then
  104.         pymv --interactive --all "$@"
  105.     else
  106.         pymv --interactive "$@"
  107.     fi
  108. }
  109.  
  110. # open files
  111. o () {
  112.     nohup xdg-open "$1" > /dev/null 2>&1 &
  113. }
  114.  
  115. # Command aliases
  116.  
  117. alias mv="move"
  118. alias cp="copy"
  119. alias ls="list"
  120. alias cd="changedir"
  121. alias rm="rm -rfI"
  122.  
  123. # Shortcuts
  124. # Do NOT name one 'i'
  125.  
  126. alias ..='changedir ..'
  127. alias ...='changedir ../..'
  128. alias ....='changedir ../../..'
  129.  
  130. z="/media/disk/"
  131. alias z="changedir $z"
  132.  
  133. x="/media/sdb4/"
  134. alias x="changedir $x"
  135.  
  136. alias h="changedir ~"
  137.  
  138. # Keybindings:
  139.  
  140. bind '"\C-g":"changedir\C-m"'
  141. bind '"\C-l":"list\C-m"'
  142. bind '"\C-H":"hide\C-m"'
  143. bind '"\C-h":"fmhelp\C-m"'
Advertisement
Add Comment
Please, Sign In to add comment