From cirrus, 3 Years ago, written in Plain Text.
  1. #      __                  _   _
  2. #     / _|_   _ _ __   ___| |_(_) ___  _ __  ___
  3. #    | |_| | | | '_ \ / __| __| |/ _ \| '_ \/ __|
  4. #    |  _| |_| | | | | (__| |_| | (_) | | | \__ \
  5. #    |_|  \__,_|_| |_|\___|\__|_|\___/|_| |_|___/
  6. #
  7. #  ▓▓▓▓▓▓▓▓▓▓
  8. # ░▓ author ▓ cirrus <cirrus@archlinux.info>
  9. # ░▓ code   ▓ https://gist.github.com/cirrusUK
  10. # ░▓ mirror ▓ http://cirrus.turtil.net
  11. # ░▓▓▓▓▓▓▓▓▓▓
  12. # ░░░░░░░░░░
  13.  
  14. ## WIKIPEDIA SEARCH FUNCTION ##
  15. wikipediaSearch() {
  16. echo -n -e "\n============================================\n\tWelcome to WikiPedia Search"; echo ""; i=1 ; for line in $(lynx --dump "http://en.wikipedia.org/w/index.php?title=Special%3ASearch&profile=default&search=$1&fulltext=Search" | grep http://en.wikipedia.org/wiki | cut -c7-); do echo $i $line; lines[$i]=$line ;  i=$(($i+1)); done ; echo -n -e "\n============================================\n\tPlease select the link to open - "; read answer; w3m ${lines[$answer]}
  17. }
  18.  
  19. ## ARCHWIKI SEARCH FUNCTION ##
  20. archSearch() {
  21. echo -n -e "\n============================================\n\tWelcome to Arch Wiki Search"; echo ""; i=1 ; for line in $(lynx --dump "https://wiki.archlinux.org/index.php?title=Special%3ASearch&profile=default&search=$1" | grep https://wiki.archlinux.org/ | cut -c7-); do echo $i $line; lines[$i]=$line ; i=$(($i+1)); done ; echo -n -e "\n============================================\n\tPlease select the link to open - "; read answer; w3m ${lines[$answer]}
  22. }
  23.  
  24. # download the aur(4) package to the current directory, similar to cower -d from the old AUR, but using the officially supported method; git.
  25. # usage:
  26. # $ aurd <package-name>
  27. aurd() {
  28.     git clone https://aur4.archlinux.org/$1.git/
  29.     #git clone ssh://aur@aur4.archlinux.org/$1.git/
  30. }
  31.  
  32. # download the aur(4) package to the current directory, cd, build (clean) and prompt to install.
  33. aurb() {
  34.     git clone https://aur4.archlinux.org/$1.git/ && cd $1 && makepkg -sci
  35.     #git clone ssh://aur@aur4.archlinux.org/$1.git/ && cd $1 && makepkg -sci
  36. }
  37.  
  38. # update the package in the current directory
  39. auru() {
  40.     git pull && rm -f *.pkg.tar.xz || true && makepkg -sci
  41. }
  42.  
  43. # Automatically do an ls after each cd
  44. cd() {
  45.   if [ -n "$1" ]; then
  46.     builtin cd "$@" && ls --group-directories-first --color=auto
  47.   else
  48.     builtin cd ~ && ls --group-directories-first --color=auto
  49.   fi
  50. }
  51.  
  52. aurctl(){
  53.           curl -s https://aur.archlinux.org/packages/"${1:0:2}/$1/$1".tar.gz | tar xz
  54.       }
  55.  
  56. #pb pastebin || Usage: 'command | pb or  pb filename'
  57. pb () {
  58.   curl -F "c=@${1:--}" https://ptpb.pw/
  59. }
  60.  
  61. pbs () {
  62.   gm import -window ${1:-root} /tmp/$$.png
  63.   pbx /tmp/$$.png
  64. }
  65.  
  66. pbx () {
  67.   curl -sF "c=@${1:--}" -w "%{redirect_url}" 'https://ptpb.pw/?r=1' -o /dev/stderr | xsel -l /dev/null -b
  68. }
  69.  
  70. ## EXTRACT FUNCTION ## | Usage: extract <file>
  71. extract () {
  72.   if [ -f $1 ] ; then
  73.       case $1 in
  74.           *.tar.bz2)   tar xvjf $1    ;;
  75.           *.tar.gz)    tar xvzf $1    ;;
  76.           *.bz2)       bunzip2 $1     ;;
  77.           *.rar)       rar x $1       ;;
  78.           *.gz)        gunzip $1      ;;
  79.           *.tar)       tar xvf $1     ;;
  80.           *.tbz2)      tar xvjf $1    ;;
  81.           *.tgz)       tar xvzf $1    ;;
  82.           *.zip)       unzip $1       ;;
  83.           *.Z)         uncompress $1  ;;
  84.           *.7z)        7z x $1        ;;
  85.           *)           echo "don't know how to extract '$1'..." ;;
  86.       esac
  87.   else
  88.       echo "'$1' is not a valid file!"
  89.   fi
  90. }
  91.  
  92. #list servicesd
  93. listd() {
  94.         echo -e ${BLD}${RED}" --> SYSTEM LEVEL <--"${NRM}
  95.         find /etc/systemd/system -mindepth 1 -type d | sed '/getty.target/d' | xargs ls -gG --color
  96.         [[ $(find $HOME/.config/systemd/user -mindepth 1 -type d | wc -l) -eq 0 ]] ||
  97.                 (echo -e ${BLD}${RED}" --> USER LEVEL <--"${NRM} ; \
  98.                 find $HOME/.config/systemd/user -mindepth 1 -type d | xargs ls -gG --color)
  99. }
  100.  
  101. # fix zsh annoying history behavior
  102. h() {
  103.      if [ -z "$*" ]; then history 1; else history 1 | egrep "$@"; fi;
  104.  }
  105.  
  106. #cd to dir of defined file | Usage: cdf <file>
  107. cdf () {
  108.   cd "$(dirname "$(locate -i "$*" | head -n 1)")" ;
  109. }
  110.  
  111. #wego weather function## | usage wttr `city`
  112. wttr () {
  113. curl http://wttr.in/$1
  114. }
  115.  
  116. #web search tool | Usage: gsearch <value>
  117. function gsearch {
  118. Q="$@";
  119. GOOG_URL='https://www.google.co.uk/search?tbs=li:1&q=';
  120. AGENT="Mozilla/4.0";
  121. stream=$(curl -A "$AGENT" -skLm 20 "${GOOG_URL}${Q//\ /+}" | grep -oP '\/url\?q=.+?&amp' | sed 's|/url?q=||; s|&amp||');
  122. echo -e "${stream//\%/\x}";
  123. }
  124.  
  125. #Convert to .mp4 | Usage: ipod5g foo.mpg
  126. ipod5g () {
  127. HandBrakeCLI -i "$1" -o "${1%.*}.ipod5g.mp4" --preset="iPod"
  128. }
  129.  
  130. #List Realtime Soccer Results | Usage: score
  131. score() {
  132.  watch -n10 --no-title "w3m http://www.livescore.com/ |awk '/live [0-9H]+[^ ]/,/red cards/'" ;
  133. }
  134.  
  135. #Is server up ? | Usage: down4me <www.foo.com>
  136. down4me() {
  137. curl -s "http://www.downforeveryoneorjustme.com/$1" | sed '/just you/!d;s/<[^>]*>//g';
  138. }
  139.  
  140. #Sprunge Paste | Usage: sprunge <file>
  141. function sprunge() {
  142.   if (($#)); then
  143. if [[ -f $1 && -r $1 ]]; then
  144. curl -F 'sprunge=<-' http://sprunge.us < "$1"
  145.     else
  146. printf 'file %s does not exist or is not readable\n' "$1" >&2
  147.       return 1
  148.     fi
  149. else
  150. curl -F 'sprunge=<-' http://sprunge.us
  151.   fi
  152. }
  153.  
  154. # Compile and execute a C source on the fly
  155. csource() {
  156.         [[ $1 ]]    || { echo "Missing operand" >&2; return 1; }
  157.         [[ -r $1 ]] || { printf "File %s does not exist or is not readable\n" "$1" >&2; return 1; }
  158.         local output_path=${TMPDIR:-/tmp}/${1##*/};
  159.         gcc "$1" -o "$output_path" && "$output_path";
  160.         rm "$output_path";
  161.         return 0;
  162. }
  163.  
  164.  
  165. ## DICTIONARY FUNCTIONS ##
  166. dwordnet () { curl dict://dict.org/d:${1}:wn; }
  167. dacron () { curl dict://dict.org/d:${1}:vera; }
  168. djargon () { curl dict://dict.org/d:${1}:jargon; }
  169. dfoldoc () { curl dict://dict.org/d:${1}:foldoc; }
  170. dthesaurus () { curl dict://dict.org/d:${1}:moby-thes; }
  171.  
  172. #internetinfo | Usage: ii
  173. function ii()   # get current host related info
  174. {
  175.     echo -e "\n${RED}Kernel Information:$NC " ; uname -a
  176.     echo -e "\n${RED}Users logged on:$NC " ; w -h
  177.     echo -e "\n${RED}Current date :$NC " ; date
  178.     echo -e "\n${RED}Machine stats :$NC " ; uptime
  179.     echo -e "\n${RED}Memory stats :$NC " ; free
  180.     echo -e "\n${RED}Disk Usage :$NC " ; df -Th
  181.     echo -e "\n${RED}LAN Information :$NC" ; netinfoLAN
  182.     echo
  183. }
  184.  
  185. #netinfo - shows LAN network information for your system (part of ii)
  186. function netinfoLAN (){
  187. echo "---------------------------------------------------"
  188. /sbin/ifconfig enp4s0 | awk /'inet/ {print $2}'
  189. /sbin/ifconfig enp4s0 | awk /'bcast/ {print $3}'
  190. /sbin/ifconfig enp4s0 | awk /'inet6 addr/ {print $1,$2,$3}'
  191. /sbin/ifconfig enp4s0 | awk /'HWaddr/ {print $4,$5}'
  192. echo "---------------------------------------------------"
  193. }
  194.  
  195. #Transfer/share any file 5GB limit | Usage: transfer ~/foo/bar
  196. transfer() { if [ $# -eq 0 ]; then echo "No arguments specified. Usage:\necho transfer /tmp/test.md\ncat /tmp/test.md | transfer test.md"; return 1; fi
  197. tmpfile=$( mktemp -t transferXXX ); if tty -s; then basefile=$(basename "$1" | sed -e 's/[^a-zA-Z0-9._-]/-/g'); curl --progress-bar --upload-file "$1" "https://transfer.sh/$basefile" >> $tmpfile; else curl --progress-bar --upload-file "-" "https://transfer.sh/$1" >> $tmpfile ; fi; cat $tmpfile; rm -f $tmpfile; }; alias transfer=transfer
  198.  
  199. # copy | Usage: copy /source/file /destination/file
  200. copy() {
  201.     size=$(stat -c%s $1)
  202.     dd if=$1 &> /dev/null | pv -petrb -s $size | dd of=$2
  203. }
  204.  
  205. # Run a command x times | Usage: runx <value>
  206. # http://www.stefanoforenza.com/how-to-repeat-a-shell-command-n-times/
  207. runx() {
  208.     n=$1
  209.     shift
  210.     while [ $(( n -= 1 )) -ge 0 ]
  211.     do
  212.         "$@"
  213.     done
  214. }
  215.  
  216. # mkdir & cd into it | Usage: mkcd
  217. mkcd() {
  218.   if [ ! -n "$1" ]; then
  219.     echo "Enter a name for this folder"
  220.   elif [ -d $1 ]; then
  221.     echo "\`$1' already exists"
  222.   else
  223.     mkdir $1 && cd $1
  224.   fi
  225. }
  226.  
  227. #Fill screen with colours | Usage: colours
  228. colours()
  229. {
  230.   _I=1
  231.   _J=0
  232.   _K=0
  233.   _WIDTH=$COLUMNS
  234.   _MARGIN=0
  235.   while true; do
  236.   _A=$(($RANDOM % 3))
  237.   _B=$(($RANDOM % 2))
  238.   _C=$(($RANDOM % 3))
  239.   case $_A in
  240.   0)
  241.     case $_B in
  242.     0)
  243.       [ $_I -gt 1 ] && _I=$(($_I - 1))
  244.     ;;
  245.     1)
  246.       [ $_I -lt 6 ] && _I=$(($_I + 1))
  247.     ;;
  248.     esac
  249.   ;;
  250.   1)
  251.     case $_B in
  252.     0)
  253.       [ $_J -gt 0 ] && _J=$(($_J - 1))
  254.     ;;
  255.     1)
  256.       [ $_J -lt 5 ] && _J=$(($_J + 1))
  257.     ;;
  258.     esac
  259.   ;;
  260.   2)
  261.     case $_B in
  262.     0)
  263.       [ $_K -gt 0 ] && _K=$(($_K - 1))
  264.     ;;
  265.     1)
  266.       [ $_K -lt 5 ] && _K=$(($_K + 1))
  267.     ;;
  268.     esac
  269.   ;;
  270.   esac
  271.   case $1 in
  272.     1)
  273.       _DELTA=$2
  274.       case $_C in
  275.         0)
  276.           [ $_WIDTH -lt $(($COLUMNS - 2*$_DELTA)) ] && _WIDTH=$(($_WIDTH + 2*$_DELTA))
  277.         ;;
  278.         1)
  279.           [ $_WIDTH -gt $((1 + 2*$_DELTA)) ] && _WIDTH=$(($_WIDTH - 2*$_DELTA))
  280.         ;;
  281.       esac
  282.       _MARGIN=$((($COLUMNS-$_WIDTH)/2))
  283.     ;;
  284.     2)
  285.       _WIDTH=$2
  286.       _DELTA=$3
  287.       case $_C in
  288.         0)
  289.           [ $_MARGIN -le $(($COLUMNS - $_WIDTH - $_DELTA)) ] && _MARGIN=$(($_MARGIN + $_DELTA))
  290.         ;;
  291.         1)
  292.           [ $_MARGIN -ge $_DELTA ] && _MARGIN=$(($_MARGIN - $_DELTA))
  293.         ;;
  294.       esac
  295.     ;;
  296.     *)
  297.       _WIDTH=$COLUMNS
  298.       _MARGIN=0
  299.     ;;
  300.   esac
  301.   _NUMBER=$((15 + $_I + 6*$_J + 36*$_K))
  302.  
  303.   echo -en "\e[0;49m"
  304.   if [ $_MARGIN -gt 0 ]; then
  305.     for _FOO in $(seq $_MARGIN); do
  306.       echo -en " "
  307.     done
  308.   fi
  309.  
  310.   printf "\e[0;48;5;${_NUMBER}m"
  311.   for _FOO in $(seq $_WIDTH); do
  312.     echo -en " "
  313.   done
  314.  
  315.   echo -e "\e[0;49m"
  316.   done
  317. }
  318.  
  319. #Search files & directories | Usage: search <file/dirs>
  320. search() {
  321. find . -iname "*$@*" | less;
  322. }
  323.  
  324. #Grep process | Usage: psgrep <process>
  325. psgrep() { ps axuf | grep -v grep | grep "$@" -i --color=auto;
  326. }
  327.  
  328. # Google images search bash function  | Usage: images <foo>
  329. images() {
  330.     search=""
  331.     for term in $*; do
  332.         search="$search%20$term"
  333.     done
  334.     xdg-open "http://www.google.co.uk/search?tbm=isch&hl=en&source=hp&biw=1366&bih=679&q=$search"
  335. }
  336.  
  337. # YouTube search bash function  | Usage: videos <foo>
  338. videos() {
  339.     search=""
  340.     for term in $*; do
  341.         search="$search%20$term"
  342.     done
  343.     xdg-open "http://www.youtube.com/results?search_query=$search"
  344. }
  345.  
  346. # DuckDuckGo search bash function  | Usage: ddg <foo>
  347. ddg() {
  348.     search=""
  349.     for term in $*; do
  350.         search="$search%20$term"
  351.     done
  352.     xdg-open "http://duckduckgo.com/?q=$search"
  353. }
  354.  
  355. # Wikipedia English search bash function   | Usage: wiki <foo>
  356. wiki() {
  357.     search=""
  358.     for term in $*; do
  359.         search="$search%20$term"
  360.     done
  361.     xdg-open "http://en.wikipedia.org/w/index.php?search=$search"
  362. }
  363.  
  364. # Android Play Store search bash function | Usage: android <foo>
  365. android() {
  366.     search=""
  367.     for term in $*; do
  368.         search="$search%20$term"
  369.     done
  370.     xdg-open "http://play.google.com/store/search?q=$search"
  371. }
  372.  
  373. # Soundcloud music bash search function  | Usage: soundcloud <foo>
  374. soundcloud() {
  375.     search=""
  376.     for term in $*; do
  377.         search="$search%20$term"
  378.     done
  379.     xdg-open "https://soundcloud.com/search?q=$search"
  380. }
  381.  
  382. # StackOverflow bash search function  | Usage: so <foo>
  383. so() {
  384.     search=""
  385.     for term in $*; do
  386.         search="$search%20$term"
  387.     done
  388.     w3m "http://stackoverflow.com/search?q=$search"
  389. }
  390.  
  391. # Pleer music bash search function  | Usage: pleer <foo>
  392. pleer() {
  393.     search=""
  394.     for term in $*; do
  395.         search="$search%20$term"
  396.     done
  397.     xdg-open "https://pleer.com/search?q=$search"
  398. }
  399.  
  400. # Amazon UK search bash function  | Usage: amazon <foo>
  401. amazon() {
  402.     search=""
  403.     for term in $*; do
  404.         search="$search%20$term"
  405.     done
  406.     xdg-open "http://www.amazon.co.uk/s/ref=nb_sb_noss_1?url=search-alias%3Daps&field-keywords=$search&x=0&y=0"
  407. }
  408.  
  409. # Dictionary | Usage define <foo>
  410. define() {
  411.     curl -s dict://dict.org/d:$1 | grep -v '^[0-9]'
  412. }
  413.  
  414. # set volume
  415. vol ()
  416. {
  417.     pactl set-sink-volume 5 $1% ;
  418. }
  419.  
  420. #encrypt <file> | Usage encrypt <file>
  421. function encrypt() {
  422.         [ -e "$1" ] || return 1
  423.         openssl des3 -salt -in "$1" -out "$1.$CRYPT_EXT"
  424.         [ -e "$1.$CRYPT_EXT" ] && shred -u "$1"
  425. }
  426.  
  427. #decrypt <file.> | Usage decrypt <file.>
  428. function decrypt() {
  429.         [ -e "$1" ] || return 1
  430.         [ "${1%.$CRYPT_EXT}" != "$1" ] || return 2
  431.         openssl des3 -d -salt -in $1 -out ${1%.$CRYPT_EXT}
  432.         [ -e "${1%.$CRYPT_EXT}" ] && rm -f "$1"
  433. }
  434.  
  435. #wallpaper changer
  436. fehpap() {
  437.         zenity --file-selection | xargs feh --bg-scale
  438.  }
  439.  
  440. unspacer() #remove spaces from files in current dir
  441. {          #replaces spaces with underscores
  442.  for i in *
  443.   do
  444.    [ ! "$i" == "$(echo $i | tr '\ ' '_')" && mv ./"$i" ./$(echo $i | tr '\ ' '_')
  445.   done
  446. }
  447.  
  448. # send link to podbeuter queue | usage podbeuter <podcasturl>
  449. podqueue() {
  450.            echo "$1 \"$HOME/Downloads/$(echo "$1" | awk -F'/' '{ print $NF }')\"" >> ~/.newsbeuter/queue ;
  451. }
  452.  
  453. myt() {
  454.         mpv ytdl://ytsearch10:"$1"
  455. }
  456.  
  457. #rtmp sniffing
  458. sniff-start() {
  459.                sudo iptables -t nat -A OUTPUT -p tcp --dport 1935 -m owner \! --uid-owner root -j REDIRECT ;
  460. }
  461.  
  462. sniff-capture() {
  463.                          rtmpsrv ;
  464. }
  465.  
  466. sniff-end() {
  467.              sudo iptables -t nat -D OUTPUT -p tcp --dport 1935 -m owner \! --uid-owner root -j REDIRECT ;
  468. }
  469.  
  470. cmdfu() { curl "http://www.commandlinefu.com/commands/matching/$(echo "$@" \
  471.         | sed 's/ /-/g')/$(echo -n $@ | base64)/plaintext" ;
  472. }
  473.  
  474.  #Show used mirrors {archlinux}
  475. mymirrors() {
  476.             grep -v '^$\|^#' /etc/pacman.d/mirrorlist | awk '{print $3}' | awk -F '/' '{print $3}';
  477. }
  478.  
  479. #URL Shortener  | Usage : short <url>
  480. short() {
  481.   curl -F"shorten=$*" https://0x0.st
  482. }
  483.  
  484. #Upload-file | Usage : share /path/to/file.foo
  485. share() {
  486.   curl -F"file=@$*" https://0x0.st
  487. }
  488.  
  489. ytconvert() {
  490.         ffmpeg -i "$1" -c:v libx264 -crf 18 -preset slow -pix_fmt yuv420p -c:a copy "$2.mkv"
  491. }
  492.  
  493. stopwatch(){
  494.     date1=`date +%s`;
  495.     while true; do
  496.     days=$(( $(($(date +%s) - date1)) / 86400 ))
  497.     echo -ne "$days day(s) and $(date -u --date @$((`date +%s` - $date1)) +%H:%M:%S)\r";
  498.     sleep 0.1
  499.     done
  500. }
  501.  
  502.  
  503. man() {
  504.     env \
  505.         LESS_TERMCAP_mb=$(printf "\e[1;31m") \
  506.         LESS_TERMCAP_md=$(printf "\e[1;31m") \
  507.         LESS_TERMCAP_me=$(printf "\e[0m") \
  508.         LESS_TERMCAP_se=$(printf "\e[0m") \
  509.         LESS_TERMCAP_so=$(printf "\e[1;44;33m") \
  510.         LESS_TERMCAP_ue=$(printf "\e[0m") \
  511.         LESS_TERMCAP_us=$(printf "\e[1;32m") \
  512.             man "$@"
  513. }
  514.  
captcha