Advertisement
lol

CrunchBang(CB)[Functions]

lol
Sep 20th, 2013
295
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.20 KB | None | 0 0
  1. # This file was made to clean up .CBBash
  2.  
  3. # [Functions]
  4.  
  5. # [ About ]
  6. function about()
  7. {
  8. clear
  9. echo -ne "      [*] OrangeKush(OK) Bash Script v.1.0"
  10. echo -e ""
  11. echo -ne "      [*] Author : Pwnsauce"
  12. echo -e ""
  13. echo -ne "      [*] EMail : sys_admin@emailengine.org"
  14. echo -e ""
  15. echo -e ""
  16. }
  17.  
  18. # [ Encryption/Decryption ]
  19. function encrypt()
  20. {
  21. gpg -ac -no-options "$1"
  22. }
  23.    
  24. function decrypt()
  25. {
  26. gpg -no-options "$1"
  27. }
  28.      
  29. # [ Extraction ]
  30. function extract()
  31. {
  32. if [ -f $1 ] ; then
  33. case $1 in
  34. *tar.bz2)   tar xvjf $1     ;;
  35. *.tar.gz)    tar xvzf $1     ;;
  36. *.bz2)       bunzip2 $1      ;;
  37. *.rar)       unrar x $1      ;;
  38. *.gz)        gunzip $1       ;;
  39. *.tar)       tar xvf $1      ;;
  40. *.tbz2)      tar xvjf $1     ;;
  41. *.tgz)       tar xvzf $1     ;;
  42. *.zip)       unzip $1        ;;
  43. *.Z)         uncompress $1   ;;
  44. *.7z)        7z x $1         ;;
  45. *)           echo "'$1' cannot be extracted via >extract<" ;;
  46. esac
  47. else
  48. echo "'$1' is not a valid file!"
  49. fi
  50. }
  51.      
  52. # Creates an archive (*.tar.gz) from given directory.
  53. function maketar() { tar cvzf "${1%%/}.tar.gz"  "${1%%/}/"; }
  54.      
  55. # Create a ZIP archive of a file or folder.
  56. function makezip() { zip -r "${1%%/}.zip" "$1" ; }
  57.      
  58. # Make your directories and files access rights sane.
  59. function sanitize() { chmod -R u=rwX,g=rX,o= "$@" ;}
  60.      
  61. function mydf()         # Pretty-print of 'df' output.
  62. {                       # Inspired by 'dfc' utility.
  63. for fs ; do    
  64. if [ ! -d $fs ]
  65. then
  66. echo -e $fs" :No such file or directory" ; continue
  67. fi
  68.      
  69. local info=( $(command df -P $fs | awk 'END{ print $2,$3,$5 }') )
  70. local free=( $(command df -Pkh $fs | awk 'END{ print $4 }') )
  71. local nbstars=$(( 20 * ${info[1]} / ${info[0]} ))
  72. local out="["
  73. for ((j=0;j<20;j++)); do
  74. if [ ${j} -lt ${nbstars} ]; then
  75. out=$out"*"
  76. else
  77. out=$out"-"
  78. fi
  79. done
  80. out=${info[2]}" "$out"] ("$free" free on "$fs")"
  81. echo -e $out
  82. done
  83. }
  84.      
  85. function my_ip() # Get IP adress on ethernet.
  86. {
  87. MY_IP=$(/sbin/ifconfig wlan0 | awk '/inet/ { print $2 } ' |
  88. sed -e s/addr://)
  89. echo ${MY_IP:-"Not connected"}
  90. }
  91.      
  92. function ii()   # Get current host related info.
  93. {
  94. echo -e "\nYou are logged on ${BRed}$HOST"
  95. echo -e "\n${BRed}Additionnal information:$NC " ; uname -a
  96. echo -e "\n${BRed}Users logged on:$NC " ; w -hs | cut -d " " -f1 | sort | uniq
  97. echo -e "\n${BRed}Current date :$NC " ; date
  98. echo -e "\n${BRed}Machine stats :$NC " ; uptime
  99. echo -e "\n${BRed}Memory stats :$NC " ; free
  100. echo -e "\n${BRed}Diskspace :$NC " ; mydf / $HOME
  101. echo -e "\n${BRed}Local IP Address :$NC" ; my_ip
  102. echo -e "\n${BRed}Open connections :$NC "; netstat -pan --inet;
  103. echo
  104. }    
  105.  
  106. export MARKPATH=$HOME/.marks
  107. function jump()
  108. {
  109.     cd -P "$MARKPATH/$1" 2>/dev/null || echo "No such mark: $1"
  110. }
  111.  
  112. function mark()
  113. {
  114.     mkdir -p "$MARKPATH"; ln -s "$(pwd)" "$MARKPATH/$1"
  115. }
  116.  
  117. function unmark()
  118. {
  119.     rm -i "$MARKPATH/$1"
  120. }
  121.  
  122. function marks()
  123. {
  124.     ls -l "$MARKPATH" | sed 's/  / /g' | cut -d' ' -f9- | sed 's/ -/\t-/g' && echo
  125. }
  126.  
  127. function completemarks()
  128. {
  129.   local curw=${COMP_WORDS[COMP_CWORD]}
  130.   local wordlist=$(find $MARKPATH -type l -printf "%f\n")
  131.   COMPREPLY=($(compgen -W '${wordlist[@]}' -- "$curw"))
  132.   return 0
  133. }
  134.  
  135. complete -F _completemarks jump unmark
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement