Created
September 6, 2013 07:34
-
-
Save anonymous/6460676 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# create a test dir stack | |
foostack() { | |
local i | |
[[ -d "$HOME/tmp" ]] && TEMPDIR="$HOME/tmp" || TEMPDIR="/tmp" | |
for ((i=1;i<10;i++)); do | |
mkdir -p "$TEMPDIR/testdir/dir-$i" && touch $TEMPDIR/testdir/{dir-$i,.}/file-{1..9} | |
done | |
echo "Done, look into $TEMPDIR/testdir" | |
} | |
# guess :) | |
goog() { | |
lynx -hiddenlinks=ignore -dump http://www.google.com/search?q="$1" | |
} | |
# check if a domain is registered | |
isreg() { | |
dig soa "$1" | grep -q ^$1 && echo "Yes" || echo "No" | |
} | |
yum_repolist() { | |
echo "showing available packages in repo $1:" | |
echo "======================================" | |
repoquery -a --repoid="$1" | |
} | |
# make dir and change into it | |
mkcd() { mkdir -p "$1" && cd "$1"; } | |
# view contents of an archive or rpm file | |
tarview() { | |
local i | |
for i in $@; do | |
if [[ ! $(file -bz $i) =~ ^(POSIX ?)?tar.*|^RPM ]]; then | |
printf "%s is not a tar archive or rpm file\n" $i | |
elif [[ $(file -bz $i) =~ ^(POSIX ?)?tar.* ]]; then | |
tput bold | |
printf '\n########### Displaying contents of %s ###########\n\n' $i; tput sgr0 | |
tar tvf "$i" | |
else | |
tput bold | |
printf '\n########### Displaying contents of %s ###########\n\n' $i; tput sgr0 | |
rpm2cpio "$i" | cpio -t | |
fi | |
done | |
} | |
alias tv='tarview' | |
# create an archive | |
car() { | |
if (( $# != 1 )); then | |
tput bold | |
echo -e "Usage:\t $FUNCNAME /path/to/folder" >&2 | |
echo -e "resulting file will be created as folder.tar.bz2" >&2 | |
tput sgr0 | |
else | |
local foo="$(basename $1)"; foo="${foo#.*}" | |
# use pbzip2 if available | |
[[ -x /usr/bin/pbzip2 ]] && tar cvf "${foo}.tar.bz2" --use-compress-prog=pbzip2 "${1}" \ | |
|| tar cvjf "${foo}.tar.bz2" "${1}" | |
(( $? == 0 )) && (tput bold; echo "$FUNCNAME: SUCCESS, created: ${foo}.tar.bz2";tput sgr0) >&2 \ | |
|| (tput bold; echo "$FUNCNAME: ERROR: archive creation failed!";tput sgr0) >&2 | |
fi | |
} | |
# add a new alias to curr shell and the ~/bash_aliases file. | |
add_alias() { | |
if [ $# -lt 2 ]; then | |
echo -e "\nUSAGE:#=> \t add_alias mynewalias \"some very long command\"" | |
else | |
local name="$1" value="$2" | |
echo alias "$name"=\'$value\' >>~/.bash_aliases | |
eval alias "$name"=\'$value\' | |
alias "$name" | |
fi | |
} | |
# wiki from cli | |
wiki() { | |
local i | |
for i in "$@"; do | |
dig +short txt "${i// /_}".wp.dg.cx | |
done | |
} | |
# cmdlinefu search | |
cmdfu() { curl "http://www.commandlinefu.com/commands/matching/$@/$(echo -n $@ | openssl base64)/plaintext"; } | |
### duplicate file finder, based on size, then md5, can take long | |
dupesfind() | |
{ | |
find -not -empty -type f -printf "%s\n" | sort -rn | uniq -d | \ | |
xargs -I{} -n1 find -type f -size {}c -print0 | xargs -0 md5sum | sort | uniq -w32 --all --repeated | |
} | |
# modinfo - info of all loaded modules | |
moduleinfo() { | |
modinfo $(cut -d" " -f1 /proc/modules) | sed '/^dep/s/$/\n/; /^file\|^desc\|^dep/!d' | |
} | |
## find the last/deepest subdirs in a given tree | |
deepest_subdirs() { | |
find "$PWD" -type d -exec bash -c 'shopt -s nullglob; d=("$1"/*/); ((!${#d[@]}))' _ {} \; -print | |
} | |
# | |
gputemp() { | |
nvidia-smi -q -a | sed -rn '/Temperature/{N; s@^[[:space:]]+@@ ; s@\n@@g; s@ +@ @g; s@([[:digit:]]+)[[:space:]](C)$@\1°\2@; p}' | |
} | |
random_string() { head -n1 <( tr -dc 'a-zA-Z0-9?!=*$%&/()' </dev/urandom | fold -w ${1:-10}); } | |
# cd .. $1 times | |
up() { | |
local i=${1:-1} p=""; while (( i-- )); do p+="../"; done; cd "$p$2" && pwd | |
} | |
pi() { | |
echo "scale=${1:-20}; 4 * a (1)" | bc -l | |
} | |
# repeat a command $1 times | |
repeat() { | |
local i n | |
n=$1; shift | |
for ((i=1; i<=n; i++)); do "$@"; done | |
} | |
#failwhale | |
fail() { | |
printf " ▄██████████████▄▐█▄▄▄▄█▌\n" | |
printf "██████▌▄▌▄▐▐▌███▌▀▀██▀▀ \n" | |
printf "████▄█▌▄▌▄▐▐▌▀███▄▄█▌ \n" | |
printf "▄▄▄▄▄██████████████ \n" | |
} | |
#roll a dice | |
dice() { | |
local i | |
for ((i=1;i<=${1:-1};i++)); do | |
head -n10 /dev/urandom | tr -dc '1-6' | cut -c1 | |
done | |
} | |
#cointoss | |
toss() { | |
local i | |
for ((i=1;i<=${1:-1};i++)); do | |
if (( "$(head -n10 /dev/urandom | tr -dc '10' | cut -c1)" == 0 )); then | |
printf "heads\n" | |
else | |
printf "tails\n" | |
fi | |
done | |
} | |
asx2avi() { | |
mencoder "$1" -ofps 23.976 -ovc lavc -oac copy -o "${1%.*}".avi | |
} | |
pbin() { | |
local i lang inter | |
if [ ! $(which shebang.pl 2>/dev/null) ]; then | |
printf "dependency script shebang.pl not found, you can download it from\n" | |
printf "http://gist.github.com/779617\n" | |
elif (($# == 0)); then | |
pastebinit -f ${lang:-text} -i - | |
else | |
for i; do | |
case "${i##*.}" in | |
pl) lang=perl;; | |
sh) lang=bash;; | |
rb) lang=ruby;; | |
xml) lang=xml;; | |
php) lang=php;; | |
*) inter=$(shebang.pl "$i"); lang="${inter:-text}";; | |
esac | |
pastebinit -f ${lang:-text} -i "$i" \ | |
|| { printf "Unknown Error, skipping: %s" "$i" | |
continue | |
} | |
done | |
fi | |
} | |
screencast() { | |
local i | |
i="${1:-$HOME/Desktop/screencast.mkv}" | |
shift | |
ffmpeg -y -f x11grab -r 25 -s 1920x1080 -i :0.0 -crf 22 -threads 3 "$i" | |
} | |
# convert currencies from one to multiple, i.e. 10 USD EUR CHF will convert 10USD to EUR and CHF | |
currency_convert() { | |
local a from to | |
a="$1" from="$2"; shift 2 | |
for to in "$@"; do | |
wget -qO- "http://www.google.com/finance/converter?a="$a"&from="$from"&to="$to"&hl=es" | sed '/res/!d;s/<[^>]*>//g' | |
done | |
} | |
monitor_traffic() { | |
local port | |
if (( $# != 0 )); then | |
port="$1"; shift | |
sudo tcpdump -tnli eth0 port "$port" | |
else | |
sudo tcpdump -tnli eth0 | |
fi | |
} | |
top_mem() { ps auxf | sort -nr -k 4 | head -"${1:-10}"; } | |
top_cpu() { ps auxf | sort -nr -k 3 | head -"${1:-10}"; } | |
latest() { local file latest; for file in "${1:-.}"/*; do [[ $file -nt $latest ]] && latest="$file"; done; printf '%s\n' "$latest"; } ## Usage: latest [dir] | |
epoch2date() { | |
local ep="$1" | |
date --date "$[$(date '+%s')-${ep}] seconds ago" '+%Y-%m-%d %H:%M:%S' | |
} | |
spin () | |
{ | |
#black="\[\033[0;30;49m\]" | |
#blackgrey="\[\033[30;47m\]" | |
red="\033[31;49m" | |
green="\033[32;49m" | |
lgreen="\033[1;32m" | |
#yellow="\033[33;49m" | |
blue="\033[34;49m" | |
#magenta="\033[35;49m" | |
#cyan="\033[36;49m" | |
white="\033[37;49m" | |
r_color="\033[0m" # Reset color | |
#clr="\033[K" # Clear to the end of the line | |
echo -ne "${red}-" && sleep 0.2 | |
echo -ne "${white}\b\\" && sleep 0.2 | |
# echo -ne "${red}-" && sleep 0.2 | |
echo -ne "${white}\b|" && sleep 0.2 | |
echo -ne "${white}\b/" && sleep 0.2 | |
# echo -ne "${white}\b-" && sleep 0.2 | |
# echo -ne "\bx" && sleep 0.2 | |
# echo -ne "${red}\b+${r_color}" && sleep 0.2 | |
echo -ne "\b" | |
} | |
http_return_code() { | |
curl -sL -w "%{http_code} %{url_effective}\n" "$1" -o /dev/null | |
} | |
who_swaps() { | |
for file in /proc/*/status ; do awk '/VmSwap|Name/{printf $2 " " $3}END{ print ""}' $file; done | sort -k 2 -n -r | less | |
} | |
top_clock() { | |
while sleep 1;do tput sc; tput bold; tput cup 0 $(($(tput cols)-29));date;tput rc;tput sgr0; done & | |
} | |
# Default bash-completion insists on expanding ~/ | |
__expand_tilde_by_ref() { true; } | |
## ++++ ALIASES ++++ ## | |
# enable color support of ls and also add handy aliases | |
if [ -x /usr/bin/dircolors ]; then | |
eval "`dircolors -b`" | |
alias ls='ls -h --color=auto' | |
alias dir='dir --color=auto' | |
alias grep='grep --color=auto' | |
alias fgrep='fgrep --color=auto' | |
alias egrep='egrep --color=auto' | |
alias lll='ls -alF --color=auto' | |
alias ll='ls -lF --color=auto' | |
alias lsd='ls -d */' | |
alias la='ls -ACF' | |
alias l='ls -CF' | |
alias ks='ls' | |
fi | |
## packagemanager | |
alias yumi="sudo yum install" | |
alias yup="sudo yum update" | |
alias yurp="sudo yum remove" | |
alias yus="yum search" | |
alias yusi="yum info" | |
alias yul='sudo yum localinstall' | |
## Misc | |
alias logout='gnome-session-save --kill' | |
## Xorg | |
alias xcat='less /etc/X11/xorg.conf' | |
alias xtree='nvidia-xconfig -c' | |
alias Xlog='less /var/log/Xorg.0.log' | |
## Custom Misc,BU-/-RE | |
alias ..='cd ..' | |
alias ...='cd ../..' | |
alias cd..='cd ..' | |
alias du='du -h' | |
alias df='df -h' | |
alias pu='pushd' | |
alias po='popd' | |
alias srcbshrc='. $HOME/.bashrc' | |
alias mount='mount | column -t' | |
alias webshare='python -c "import SimpleHTTPServer; SimpleHTTPServer.test();"' | |
alias gmnext='gmusicbrowser -launch_or_cmd NextSong' | |
alias lh='ls -d .*' | |
alias p='pstree -p' | |
alias -- +w='chmod a+w' | |
alias -- -w='chmod a-w' | |
alias -- +r='chmod a+r' | |
alias -- -r='chmod a-r' | |
alias -- +x='chmod a+x' | |
alias -- -x='chmod a-x' | |
# WAN IP | |
alias myip4='curl ipv4.icanhazip.com' | |
alias myip6='curl icanhazip.com' | |
alias myip=myip4 | |
alias net_open_ports='lsof -iTCP -sTCP\:LISTEN -P' | |
alias ös='ls' | |
## gmusicbrowser | |
# query currently playing song | |
gm_i() { | |
dbus-send --print-reply --dest=org.gmusicbrowser /org/gmusicbrowser org.gmusicbrowser.CurrentSong | \ | |
sed -ne '/"\(artist\|title\|album\)"/ { s/string//p ;n; s/string//;p}' | |
} | |
alias gm_info='dbus-send --print-reply --dest=org.gmusicbrowser /org/gmusicbrowser org.gmusicbrowser.CurrentSong' | |
alias gm_play='dbus-send --dest=org.gmusicbrowser /org/gmusicbrowser org.gmusicbrowser.RunCommand string:PlayPause' | |
alias gm_time='dbus-send --print-reply --dest=org.gmusicbrowser /org/gmusicbrowser org.gmusicbrowser.GetPosition' | |
alias gm_next='dbus-send --dest=org.gmusicbrowser /org/gmusicbrowser org.gmusicbrowser.RunCommand string:NextSong' | |
################################################# | |
# COLORS | |
# [\033[0;31m determines the text color—just change the numbers. | |
# [\033[m turns off the colors, so that your commands and command output will return to the normal shell colors | |
#black="\033[0;30m" | |
#darkgrey="\033[1;30m" | |
#blue="\033[0;34m" | |
#lightblue="\033[1;34m" | |
#green="\033[0;32m" | |
#lightgreen="\033[1;32m" | |
#cyan="\033[0;36m" | |
#lightcyan="\033[1;3#6m" | |
#red="\033[0;31m" | |
#lightred="\033[1;31m" | |
#purple="\033[0;35m" | |
#lightpurple="\033[1;35m" | |
#brown="\033[0;33m" | |
#yellow="\033[1;33m" | |
#lightgrey="\033[0;37m" | |
#white="\033[1;37m" | |
##orange="\033[1;31m" | |
#r_color="\033[0m" # Reset color | |
#clr="\033[K" #clear to the end of the line | |
alias local_repo='createrepo -u $HOME/rpmbuild/RPMS $HOME/rpmbuild/RPMS' | |
alias wetter='curl http://weather.noaa.gov/pub/data/observations/metar/decoded/EDDH.TXT 2>/dev/null' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment