Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- unalias -a # Delete all aliases
- #> new name, i don't *think* it conflicts with something
- #= same as original command, *shouldn't* modify the normal behaviour
- #! same as original command, *probably* breaks normal behaviour
- #######################################################################
- #_ Aliases: ~/.bash/aliases_functions.sh -- by yunga.palatino@gmail.com
- alias aliasinfo="perl -nlE'say qq@\n\n***** \$1@ if /#_\s+(.*)/;say qq@\$1\t\$2@ if /^alias\s+(\w+?)=.*?#([>!=:]\s+.*)/' ~/.bash/aliases_functions.sh | less" #> Display this help
- alias reloadaliases="source ~/.bash/aliases_functions.sh" #> Reload aliases, deletes ALL aliases
- alias realias="vim ~/.bash/aliases_functions.sh; source ~/.bash/aliases_functions.sh" #> Edit and reload aliases, deletes ALL aliases
- #alias cliref="less ~/.bash/docs/cliref.md" #> Unix CLI Reference
- alias cliref="curl -s http://pastebin.com/raw.php?i=yGmGiDQX | less -i" #> Unix CLI Reference (online)
- #######################################################################
- #_ Navigate
- alias cd..='cd ..' #> cd: yes, i was using dos first !#@?
- alias ..='cd ..' #> cd: Norton Dos, in fact.... (which was better than 4Dos IMHO)
- alias ...='cd ../..' #> cd:
- alias ....='cd ../../..' #> cd: and i like long directory trees ;-)
- alias .....="cd ../../../.."
- alias -- -='cd -' #> cd: go back to previous directory
- alias tree='tree --dirsfirst -aDF' #! tree: dirs first, all files, show last modified date
- alias mkdir='mkdir -p' #= mkdir: create nested subdirs too
- #######################################################################
- #_ List files, ls should be used to list files, and not be an alias
- #alias ls='ls --color=auto --quoting-style=shell-always --group-directories-first -Fx' #! ls: colors, quoted, dirs first, (F)ile type, horizontaly (x)
- alias l='ls --color=auto --quoting-style=shell-always --group-directories-first -FxX' #> ls: grouped by e(X)tensions
- alias l.='ls --color=auto --quoting-style=shell-always --group-directories-first -Fxad .*' #> ls: (a)ll files, don't list (d)ir content and don't derefernce, starting with .
- alias ll='ls --color=auto --quoting-style=shell-always --group-directories-first -Flh' #> ls: (l)ong, (h)uman-readable
- alias la='ls --color=auto --quoting-style=shell-always --group-directories-first -Flha' #> ls: (l)ong, (h)uman-readable, (a)ll files
- alias lt='ls --color=auto --quoting-style=shell-always -Flhart' #> ls: (l)ong, (h(uman-readable, (a)ll files, by (r)reverse (t)ime (recent goes last)
- alias lT='ls --color=auto --quoting-style=shell-always -Flhat' #> ls: (l)ong, (h(uman-readable, (a)ll files, by (t)ime (oldest goes last)
- alias ltc='ls --color=auto --quoting-style=shell-always -Flharct' #> ls: (l)ong, (h(uman-readable, (a)ll files, by (r)reverse (c)(t)ime (recent goes last)
- alias lTc='ls --color=auto --quoting-style=shell-always -Flhact' #> ls: (l)ong, (h(uman-readable, (a)ll files, by (c)(t)ime (oldest goes last)
- alias lz='ls --color=auto --quoting-style=shell-always -FlharS' #> ls: (l)ong, (h(uman-readable, (a)ll files, (r)everse si(z)e (biggest goes last)
- alias lZ='ls --color=auto --quoting-style=shell-always -FlhaS' #> ls: (l)ong, (h(uman-readable, (a)ll files, (r)everse si(z)e (smallest goes last)
- alias lx='ls --color=auto --quoting-style=shell-always --group-directories-first -FxXlah' #> ls: horizontaly (x), grouped by e(X)tensions, (a)ll, (h)uman-readable, extension
- alias lsd='ls --color=auto --quoting-style=shell-always --group-directories-first -Fxad */' #> ls: (a)ll files, don't list (d)ir content and don't derefernce, glob on directories
- # [ATTN] nocaseglob and [[:regex:]] doesnt cooperate nicely, this is just for listing
- alias lU='shopt -u nocaseglob; ls --color=auto --quoting-style=shell-always --group-directories-first -Fdl [[:upper:]]*; shopt -s nocaseglob' #> ls: files/dirs begining with an uppercase letter !this is buggy!nocaseglob!
- alias lu='shopt -u nocaseglob; ls --color=auto --quoting-style=shell-always --group-directories-first -Fdl [[:lower:]]*; shopt -s nocaseglob' #> ls: files/dirs begining with an lowercase letter !this is buggy!nocaseglob!
- #######################################################################
- #_ Find files
- alias ff='find . -iname' #> find: files subdirs, case (i)nsensitive
- alias fl='find .' #> find: list all files in subdirs (with ./ relative path)
- alias flist="find . | bzip2 -9 > flist.txt.bz2" #> find: fl > flist.txt.bz2
- alias flabs='find `pwd`' #> find: list all files in subdirs (with absolute filename)
- alias loc='locate -i' #> locate: find files from update db, case insensitive
- alias locf='locate -bei' #> locate: find files from update db, only the basename, case insensitive, and if file still exists
- #######################################################################
- #_ Look at files
- alias P='less' #> more/less/most: default pager
- alias H='head -$(($LINES/5*3))' #> head: Show the first lines of a file
- alias T='tail -$(($LINES/5*3))' #> tail: Show the last lines of a file
- alias Tf='tail -$(($LINES/5*3)) -f' #> tail: Show the last lines of a file and follow
- alias skip='gawk "NR<=1{next}{print}"' #> gawk: skip first line of file [TODO] should be a function
- alias skeep="gawk 'NR<=1{printf \"!\"}{print}'" #> gawk: prepend "!" to the first line (so it is sorted first, this and awful hack i know)
- alias trimspc='perl -plE"s/\s+/ /g; s/^\s+//g; s/\s+$//g"' #> perl: remove spaces (start/end/double)
- alias C='column -t' #> column: Format space separted value in colmns (nicely?), add -ns "sep" to define a separator
- alias L='wc -l' #> wc: count (l)ines
- alias filez='file -kLpsz' #> file: search more than one filetype, dereference links, preserve date (pretend not having read them), special files, uncompress
- alias g='grep --color=auto -Pi' #> egrep: colors, (P)erl regexes, (R)ecurse dirs and case (i)nsensitive (i assume LC_ALL=C)
- alias G='grep --color=auto -Piv' #> egrep: in(v)ert match, colors, (P)erl regexes, (R)ecurse dirs and case (i)nsensitive (i assume LC_ALL=C)
- alias g+='agrep -i' #> agrep: case (i)sensitive, for grepping differently (AND and OR operators, checkit!)
- alias stringz='strings -a' #> strings: show (a)ll
- alias stringx='strings -atx' #> strings: show (a)ll, print hex offsets
- alias E='vim -' #> vim: Edit stdin
- alias V='mcview' #> mcView:
- alias X='mcedit' #> mcedit: (for the heX editor)
- #alias hex='hexdump -C' #> Canonical hexdump ofs hex ascii (you can use od/xxd instead)
- alias hex='xxd -a -c 32 -g 4' #> xxd: hexdump, (a)utoskip 32bytes/line (xxd comes with vim) -> hex file.org dump
- alias hexpatch='xxd -r -a -c 32 -g 4' #> xxd: apply hexdump -> hexpatch modified_dump file.org
- alias ddiff='LC_ALL=C TZ=GMT0 diff -Naur' #>normalise diffs for distribution
- #diff='diff -bBiEwu
- #######################################################################
- #_ Sorting
- alias S='sort -f' #> sort: case insensitive (f)olding (see LC_COLLATE)
- alias SP='sort -f | P' #> sort: Sort, case insensitive (f)olding, results in pager
- alias SU='sort -uf' #> sort: case insensitive, (u)nique lines
- alias SD='sort -f | uniq -id' #> sort:uniq: case insensitive (f)olding, (d)uplicate lines
- alias SN='sort -fn' #> sort: case insensitive (f)olding, (n)umerical
- alias SUP='sort -uf | P' #> sort: case insensitive, (u)nique lines, results in pager
- alias SDP='sort -f | uniq -id | P' #> sort:uniq: case insensitive (f)olding, (d)uplicate lines, results in pager
- alias SNP='sort -fn | P' #> sort: case insensitive (f)olding, (n)umerical, results in pager
- alias SUL='sort -uf | wc -l' #> sort:wc: sort, uniq, count lines
- # [TODO] comm: add aliases for union, intersection and delta
- # see: http://www.catonmat.net/blog/set-operations-in-unix-shell/
- #######################################################################
- #_ Access rights
- alias R='chmod -Rc' #> chmod: (R)ecurse, (c) verbose
- alias O='chown -Rc' #> chown: (R)ecurse, (c) verbose
- #######################################################################
- #_ Used/Free mounted disk/memory
- alias dfs='df -PTah --sync | sort -f | column -t' #> df: (P)osix format, show fs (T)ype, (a)ll, (h)uman read-able, sync first
- alias dfi='df -PTai --sync | sort -f | column -t' #> df: (P)osix format, show fs (T)ype, (a)ll, show (i)nodes informations instead of blocks, sync first
- alias dfw='watch --differences -n 5 "df -PTah --sync | sort -f | column -t"' #> df: watch df, update every 5sec, highlight differences
- alias mounted='mount | sort -f | column -t' #> mount: formatted nicely
- alias uspc='du -h --max-depth=1' #> du: current dir and subdirectorires
- alias free='free -tm' #! free mem, swap, (t)otal in (m)ega bytes
- #######################################################################
- #_ Perl
- alias p='perl -nlE' #> perl: process file by line, chomp
- alias pcsv='perl -naF"," -lE' #> perl: autosplit for csv files
- alias ptsv='perl -naF"\t" -lE' #> perl: autosplit for tab separated values files
- alias pspc='perl -naF"\s+" -lE' #> perl: autosplit for blank space separated values files
- alias pp='perl -plE' #> perl: process file by line, chomp and print
- alias pdbg='perl -dE 1' #> perl: perl debugger
- alias dpl='perl -MO=Deparse' #> perl: show how perl see this code
- alias dpl2='perl -MO=Deparse,-p,-q,-sCT' #> perl: show how perl see this code, with parens and more
- alias cpan='perl -MCPAN -E shell' #> perl: Start CPAN
- function pmod { perl -M$1 -E 'print join "\t", $ARGV[0], $ARGV[0]->VERSION' $1; }
- #######################################################################
- #_ Processes and jobs
- alias psaux='ps ax --cols 1024 --format pid,euser,egroup,pri,nice,start,etime,%cpu,vsize,tty,args | less' #> ps: custom format...
- alias pstree='pstree -Aplnu | P' #! pstree: (A)SCII, (p)ids, (l)ong lines, sort by ancestor pid (n)umber, show (u)id changes
- alias j='jobs -l' #> jobs: (l)ist process id too
- alias top10="uname -a; uptime; echo; ps -eo pcpu,rss,stime,user,pid,cmd --sort -pcpu | head -11 | column -t | cut -c -$COLUMNS; echo; ps -eo vsize,rss,size,stime,user,pid,cmd --sort -rss | head -11 | column -t | cut -c -$COLUMNS; echo; free -mt" #> top 10 cpu/memory processes
- #alias psg='ps aux | egrep -i' #> use pgrep instead
- #######################################################################
- #_ Debugging
- alias strace='strace -Ff -ttt -T -C -v -a 128' #! strace: trace (F)orked child, output to (f)ile.pid, unix (ttt)imestamp, elapsed (T)ime, (C) time/calls/errors + summary, print en(v)ironment, ret v(a)l on column 128
- #######################################################################
- #_ Network
- alias N='netstat -tulpn' #> netstat: Show Netword Connections, don't resolve hotnames
- alias NN='ss -rape | P' #> ss: all types, processes infos, detailled infos
- alias NNN='netstat -tupae' #> netstat: Show Network Connection, resolve hostnames
- alias NS='netstat -nat | awk '\''NR<=2{next} {print $6}'\'' | sort | uniq -c; echo; ss -s' #> netstat:ss: Summary of Network Connections States
- # [TODO] unhide-tcp, lsof, mtr, netwox
- alias sprunge='curl -F "sprunge=<-" http://sprunge.us' #> curl: Send stdin to http://sprunge.us/ see also pastebinit
- alias internet_addr='lynx -dump http://ifconfig.me/all | egrep "ip_addr|remote_host"' #> lynx: fetch http://ifconfig.me/all and display ip address and hostname as seen from the intertubes
- alias W='lynx' #> lynx/links
- alias WS='lynx -source' #> lynx: Web Page Source
- alias WD='lynx -dump -justify -hiddenlinks=merge -image_links -ismap' #> lynx: Web Page Dump (formatted html)
- alias WL='lynx -dump -justify -hiddenlinks=merge -image_links -ismap -nonumbers -listonly' #> lynx: Web Page Links Dump
- alias WF='lynx -dump -justify -hiddenlinks=merge -image_links -ismap -nonumbers -listonly -stdin' #> lynx: Format HTML Document from stdin
- alias WH='lynx -dump -head' #> lunx: dump webserver headers
- alias Wcp='wget --recursive --no-clobber --page-requisites --adjust-extension --convert-links --restrict-file-names=windows,lowercase --no-parent --user-agent="Googlebot/2.1 (+http://www.googlebot.com/bot.html)"' #> wget: copy website "http://example.com/dir/*" add -nd to save without the directories, see also httrack
- # [TODO] wget conditional: add cookies support / referrer
- alias FreeDNS='echo -e "DnsAdvantage: 156.154.70.1 156.154.71.1\nDynDNS: 216.146.35.35 216.146.36.36\nEpimeros: 46.4.27.2\nGeekNode: 81.93.248.69 81.93.248.68 91.194.60.196 193.17.192.53\nGoogle: 8.8.8.8 8.8.4.4\nLegtux: 88.190.27.51\nNorton: 198.153.192.1 198.153.194.1\nOpenDNS: 208.67.222.222 208.67.220.220\nScrubIt: 67.138.54.100 207.225.209.66\nTelecomix: 91.191.136.152 85.229.85.109\nVerizon: 4.2.2.1 4.2.2.2 4.2.2.3 4.2.2.4 4.2.2.5 4.2.2.6"' #> echo: display a list of dns servers (not crippled) 2001:4860:4860::8888 and/or 2001:4860:4860::8844
- alias httpserv="python -m 'SimpleHTTPServer'" #> python: serve the current directory as a static website
- #######################################################################
- #_ Packages Management (needs apt-file)
- alias pkgprovides='dpkg -S' #> dpkg: which package provides an installed file?
- alias pkginstalls='dpkg -L' #> dpkg: show the files a packages installs
- alias pkginstalled='dpkg --get-selections' #> dpkg: list installed packages
- alias pkginfo='apt-cache show' #> apt-cache: show packages informations
- alias pkgsearch='apt-cache --names-only search' #> apt-cache: grep packages names
- alias pkgsearchdesc='apt-cache search' #> apt-cache: grep packages names and descriptions
- alias pkgcontains='apt-file -i list' #> apt-file: search filenames (-l for pkgnames)
- alias pkgseek='apt-file search' #> apt-file: search files and directories (-l for pkgnames)
- alias pkgsim='apt-get --simulate --no-install-recommends install' #> apt-get: simulate install
- alias pkgsimfull='apt-get --simulate install' #> apt-get: simulate install with recommendations
- alias pkgupdate='sudo apt-get update && sudo apt-get upgrade' #> apt-get: update packages
- #######################################################################
- #_ Calculations and Units convertions
- alias Q="qalc" #> qalc: quick calculations/units & money conversion (http://qalculate.sf.net/)
- alias bc='bc -ql' #= bc: should be quiet, and with mathlib
- alias units='units -qv' #! units: should be quiet AND verbose (guess that one)
- alias cls='echo -e \\033c;reset;clear' #> reset:clear: Reset terminal, clear screen
- #######################################################################
- #_ Various
- alias dmsg='dmesg | less' #> dmesg: List kernel boot messages
- #alias h='pman' #> pman: manual page browser
- alias mrproper='find . \( -type f -and -iname \*.bak -or -iname \*.bck -or -iname \*~ \) -exec rm -f "{}" \;' #> Delete backups and other temp files
- alias notes="vim $NOTES" #> $EDITOR $NOTES [TODO] should be a function with gpg
- alias t='todo' #> (Gina Trapani's http://todotxt.com/)
- alias tar='tar -b 32768 --atime-preserve' #! tar: (b)lock size ~16M are ok (faster/smaller), no access time modifications
- alias Z='sudo' #> sudo (should add alias judo='sudo !!', sometimes you know you suck with ubuntu)
- alias hr='echo -e "\n##==------------------------------------\n"' # echo horizontal line of 40 chars (starting with ##==--)
- alias minicom='minicom -c on' #! minicom: enable (c)olors (hell, yes, it's been years i haven't used that, but i'm kind of nostalgic about it)
- alias XArgs='xargs -I{} -P8 -n1' #> xargs: 8 processes simultaneously
- alias xevkeys='xev | grep -A2 --line-buffered "^KeyRelease" | sed -n "/keycode /s/^.*keycode \([0-9]*\).* (.*, \(.*\)).*$/\1 \2/p"' #> xev: show X11 keycodes and keynames
- alias isprime="perl -wle 'print qq!Prime! if (1 x shift) !~ /^1?$|^(11+?)\1+$/'" #> check if a number below 65536 is prime
- alias githubmd='curl https://api.github.com/markdown/raw -s -XPOST -H Content-Type:text/plain -d @-'
- #######################################################################
- # Use the same editor
- #alias gvim="gvim --servername VIM_$USER --remote-silent" #! use the same gvim for every edit
- #alias vim="vim --servername VIM_$USER --remote-silent" #! use the same vim for every edit
- #alias vi="vim --servername VIM_$USER --remote-silent" #! no vi
- #######################################################################
- #_ Stupid aliases
- alias fortune='fortune -ao' #= fortune: Take (a)ll/(o)ffensive fortunes
- alias snes='snes9x -y3 -dfr' #> snes9x: 2xSaI mode, show framerate
- #######################################################################
- #_ Date/Time Stamps
- alias ts="date -u +%Y%m%d_%H%M%S" #> date: Output a timestamp (UTC). Touch `ts`-newfile. Format: +%Y%m%d_%H%M%S
- alias tsd="date -u +%Y%m%d" #> date: Output only the date
- alias tsh="date -u +%H%M%S" #> date: Output only the time (tst conflicts pvm, besides it's misleading)
- #alias terminfo="infocmp -1 | sed -nu 's/^[ \000\t]*//;s/[ \000\t]*$//;/[^ \t\000]\{1,\}/!d;/acsc/d;s/=.*,//p'|column -c80" #> infocmp: display terminal capabilities
- #######################################################################
- #_ X aliases
- alias G="gqview" #> gqview
- alias D0='export DISPLAY=:0' #> export DISPLAY=:0
- alias DS='echo DISPLAY=$DISPLAY TERM=$TERM LINES=$LINES COMLUMNS=$COLUMNS' #> shows $DISPLAY $TERM $LINES and $COLUMNS
- alias DExp='xhost +' #> xhost: + you can replace with +localhost or +si:localuser:username +local:local
- alias xterm='xterm -fb "" -bg black -fg gray -fa "Sans Mono" -fs 9 +sb -sl 3000 -g 80x50+1+1' #! xterm: font and color preferences
- #######################################################################
- #_ Clipboard
- alias CC='xclip -selection clipboard' #> xclip: Copy stdin to X clipboard, add -f to use as a filter
- alias CV='xclip -o -selection clipboard' #> xclip: Paste (o)uput clipboard to stdout
- alias CS='xclip -o -selection primary' #> xclip: Paste selection
- # Cygwin's clipboard
- if [ `uname -o` = "Cygwin" ]; then
- alias CC='putclip -n'
- alias CV='getclip -n'
- alias CS='getclip -n'
- fi
- #######################################################################
- # Being cautious on mondays...
- #if [[ $(date +%u) -eq 1 ]]; then
- # alias rm='rm -i'
- # alias cp='cp -i'
- # alias mv='mv -i'
- #fi
- #######################################################################
- #_ Directories operations: mc() md() rd mdtmp()
- # MC
- unset -f mc
- function mc () { #! mc: cd to last selected directory (from Torben Fjerdingstad)
- mkdir -pm 0700 $HOME/.mc/tmp 2>/dev/null;
- OLD_TERM=$TERM
- TERM='xterm'
- MC=$HOME/.mc/tmp/mc-$$;
- TERM=$OLD_TERM
- /usr/bin/mc -a -P $MC "$@";
- cd "`cat $MC`";
- rm -f "$MC";
- unset -v OLD_TERM MC;
- }
- # Directory creations
- unset -f md
- function md () { #! mkdir:cd: mkdir and cd into it
- mkdir -p "$*" && cd "$*"
- }
- #! rm: Remove non-empty directories
- alias rd="rm -Rf"
- unset -f mdtmp #! create a temporary dir and set $TSTMP
- function mdtmp () {
- export TSTMP="~/tmp/`date -u +%Y%m%d_%H%M%S`-$1";
- mkdir -p "$TSTMP";
- }
- #######################################################################
- #_ Save a copy of the file: save() edit()
- unset -f save
- function save() {
- cp "$1" "$1.`date -u +%Y%m%d_%H%M%S`.$USER.sav"
- }
- # Safe Edit
- unset -f edit
- function edit () {
- cp "$1" "$1.`date -u +%Y%m%d_%H%M%S`.$USER.sav"
- vim "$1"
- }
- #######################################################################
- #_ Scripts Record/Replay: scriptrec() scriptplay()
- # Save scripts for replay
- unset -f scriptrec
- function scriptrec () {
- local SCRIPT="$1.script"
- local TMPDIR="$TMP/`date -u +%Y%m%d_%H%M%S`-$SCRIPT"
- local TIMINGS="$SCRIPT.timings"
- local OUTFILE="$SCRIPT.tar.bz2"
- mkdir -pm 0700 "$TMPDIR"
- script -t "$TMPDIR/$SCRIPT" 2> "$TMPDIR/$TIMINGS"
- echo Usage: scriptreplay "$SCRIPT" "$TIMINGS" 3.5 > $TMPDIR/README
- tar -cj -C "$TMPDIR" -f "$OUTFILE" "$SCRIPT" "$TIMINGS" README
- rm -Rf $TMPDIR
- }
- # Replay a saved script with turbo 3.5x (looks good here)
- unset -f scriptplay
- function scriptplay () {
- local SCRIPT=${1%.tar.bz2}
- local TMPDIR="$TMP/`date -u +%Y%m%d_%H%M%S`-$SCRIPT"
- local TIMINGS="$SCRIPT.timings"
- mkdir -pm 0700 "$TMPDIR"
- tar -xj -C "$TMPDIR" -f "$1"
- scriptreplay "$TMPDIR/$SCRIPT.timings" "$TMPDIR/$SCRIPT" 3.5
- rm -Rf $TMPDIR
- }
- #######################################################################
- #_ From bash_aliases docs for csh compatibility: setenv() unsetenv
- alias unsetenv=unset
- unset -f setenv
- function setenv () {
- export $1="$2"
- }
- #######################################################################
- #_ Path tools: showpath loadpath() appendpath() prependpath()
- alias showpath='echo -e ${PATH//:/\\n}'
- unset -f loadpath
- function loadpath () {
- local LINE=1
- local DIR
- local NEWPATH
- while read -r DIR; do
- DIR=${DIR%#*} # remove comments
- DIR=${DIR##*([$' \t\n'])} # trim trailling spaces
- DIR=${DIR%%*([$' \t\n'])}
- eval "DIR=\"$DIR\"" # evaluate vars
- if [[ $DIR ]]; then
- if [[ -d "$DIR" && -r "$DIR" ]]; then
- NEWPATH="$NEWPATH:$DIR"
- else
- echo loadpath: Discarded "$DIR" at line $LINE from your PATH.
- fi
- fi
- let LINE=LINE+1
- done < $1
- if [[ $NEWPATH ]]; then
- export PATH=$NEWPATH
- else
- echo loadpath: Empty new path, your old PATH has been preserved.
- fi
- unset -v LINE DIR NEWPATH
- }
- # add to the end of path
- unset -f appendpath
- function appendpath () {
- if ! eval test -z "\"\${$1##*:$2:*}\"" -o -z "\"\${$1%%*:$2}\"" -o -z "\"\${$1##$2:*}\"" -o -z "\"\${$1##$2}\"" ; then
- eval "$1=\$$1:$2"
- fi
- }
- # add to the front of path
- unset -f prependpath
- prepend_path() {
- if ! eval test -z "\"\${$1##*:$2:*}\"" -o -z "\"\${$1%%*:$2}\"" -o -z "\"\${$1##$2:*}\"" -o -z "\"\${$1##$2}\"" ; then
- eval "$1=$2:\$$1"
- fi
- }
- #######################################################################
- #_ Escape a filename properly: shquot()
- shquot () {
- local quoted=${0/\'/\'\\\'\'}
- echo "'$quoted'"
- }
- #######################################################################
- #_ Repeat n times command: repeat()
- function repeat() {
- local i max
- max=$1; shift;
- for ((i=1; i <= max ; i++)); do # --> C-like syntax
- eval "$@";
- done
- }
- #######################################################################
- #_ Get some informations: hi()
- function hi() {
- echo -ne "\nHi $USER!\n\nYou are logged on: "; uname -a
- echo -ne "\n*** On `date -u +%Y%m%d_%H%M%S`";
- echo -ne "Uptime is "; uptime
- echo -ne "\n*** Memory stats:\n"; free -tm
- echo -ne "\n*** Users logged on: "; w -h
- local MY_IP=$(ifconfig eth0 | awk '/inet/ { print $2 } ' | sed -e s/addr://)
- local INET_IP=$(wget -qO - icanhazip.com)
- echo -ne "\n*** Local IP Address: "; echo ${MY_IP:-"Not connected"}
- echo -ne "*** Internet IP Address: "; echo ${INET_IP:-"Not connected"}
- }
- #######################################################################
- #_ Ask Yes/No: ask()
- function ask() {
- local ans
- echo -n "$@" '[y/N] ' ; read ans
- case "$ans" in
- y*|Y*) return 0 ;;
- *) return 1 ;;
- esac
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement