I am at ${HOME} downloads
Where you at? 😆

The usefulness of an ‘.aliases.sh’, and a ‘.functions.sh’ file.

Since I appear to be reusing “ disproportionate ” amounts of code snippets (i.e. I recycle a lot) in my bash scripting related posts. Therefore, why not have one page to point at all of those!? 😆

Operation “ deobfuscate ” is a go! 😉

Let’s start from the beginning shall we. 🙂
(It appears that the “ \ ” gets stripped out by wordpress’ automated ‘spellchecker’!?
Hardcoding the “ \ ” as &#x5c ; seems to solve the problem. 😉 )

Everytime you login to your box, you’re technically logging into a “bash login shell”, and not as some might expect a {da,a,}sh shell. ← The latter typically gets used to boot up your box, in a very quick fashion, but more on that later! 😉

Anyway!

The first file that gets read in by your login shell is the so called “.profile” file, and it’s typically located here: ~/.profile

# ~/.profile: executed by the command interpreter for login shells.
# This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login
# exists.
# see /usr/share/doc/bash/examples/startup-files for examples.
# the files are located in the bash-doc package.

# the default umask is set in /etc/profile; for setting the umask
# for ssh logins, install and configure the libpam-umask package.
#umask 022

# if running bash
if [ -n "$BASH_VERSION" ]; then
    # include .bashrc if it exists
    if [ -f "${HOME}/.bashrc" ]; then
	. "${HOME}/.bashrc"
    fi
fi

# set PATH so it includes user's private bin if it exists
if [ -d "${HOME}/bin" ] ; then
    PATH="${HOME}/bin:$PATH"
fi

As you can see from the following “snippet”, I’ve added a few thingies. 😉 Among things, I’ve put in a path to my very own little script folder, and as I’ve recently added a portable texlive install, at a custom location. I need(ed) to tell my system where to find its binaries, hence the placement of the new “$PATH”, in front of the old one. 😉 More about on how to install LaTeX, and how to use your own scripts, at a later time (of my convenience.).


## Path to local scripts.
if [ -d "${HOME}/.usr/bin" ];then
    PATH="${HOME}/.usr/bin:$PATH"
fi
##  Path to texlive-2013 portable installation.
TeXLive="/vault/texlive.portable/bin/x86_64-linux"
if [ -d "$TeXLive" ];then
    PATH="$TeXLive:$PATH"
fi

Back to top.

Next up, we’ll discuss the following file, which gets executed by your “bash-login-shell”. It’s the so called “.bashrc” file, and it’s typically located here: ~/.bashrc

# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples

# If not running interactively, don't do anything
[ -z "$PS1" ] && return

# don't put duplicate lines or lines starting with space in the history.
# See bash(1) for more options
HISTCONTROL=ignoreboth

# append to the history file, don't overwrite it
shopt -s histappend

# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=1000
HISTFILESIZE=2000

# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize

# If set, the pattern "**" used in a pathname expansion context will
# match all files and zero or more directories and subdirectories.
#shopt -s globstar

# make less more friendly for non-text input files, see lesspipe(1)
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"

# set variable identifying the chroot you work in (used in the prompt below)
if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then
    debian_chroot=$(cat /etc/debian_chroot)
fi

# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
    xterm-color) color_prompt=yes;;
esac

# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
#force_color_prompt=yes

if [ -n "$force_color_prompt" ]; then
    if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
	# We have color support; assume it's compliant with Ecma-48
	# (ISO/IEC-6429). (Lack of such support is extremely rare, and such
	# a case would tend to support setf rather than setaf.)
	color_prompt=yes
    else
	color_prompt=
    fi
fi

if [ "$color_prompt" = yes ]; then
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
unset color_prompt force_color_prompt

# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
    PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
    ;;
*)
    ;;
esac

# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
    test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
    alias ls='ls --color=auto'
    #alias dir='dir --color=auto'
    #alias vdir='vdir --color=auto'

    alias grep='grep --color=auto'
    alias fgrep='fgrep --color=auto'
    alias egrep='egrep --color=auto'
fi

# some more ls aliases
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'

# Add an "alert" alias for long running commands.  Use like so:
#   sleep 10; alert
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || \
echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'

# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.

if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
fi

# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
    . /etc/bash_completion
fi

Back to top.

Link here:

And here is mine, in which I only highlight the changes I made:

if [ "$color_prompt" = yes ]; then
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]I am @: \[\033[00m\]\[\033[01;34m\]\w\[\033[00m\]/'
else
    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
unset color_prompt force_color_prompt

# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
    PS1="\[\033]0;${debian_chroot:+($debian_chroot)}I am a FREE Elf! \u@\h: \w\a\]$PS1"
    ;;
*)
    ;;
esac

# Add an "alert" alias for long running commands.  Use like so:
#   sleep 10; alert
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || \
echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
##  If I hardcode my paths, for my convenience,
##  then I expect bash_completion to honor those,
##  instead of escaping them with '\'... Ugghhhh ← Bad design move. : (
##  See: http://askubuntu.com/questions/41891/bash-auto-complete-for-environment-variables
if
  ((BASH_VERSINFO[0] >= 4)) && ((BASH_VERSINFO[1] >= 2))
then
  shopt -s direxpand
fi
##  Miscellaneous
export Aliases="${HOME}/.aliases.sh"
export Functions="${HOME}/.functions.sh"
export Completions="/etc/bash_completion"
##  Alias definitions.
##  You may want to put all your additions into a separate file like
##  ~/.bash_aliases, instead of adding them here directly.
##  See /usr/share/doc/bash-doc/examples in the bash-doc package.
if [[ -f "$Aliases" ]];then . "$Aliases";fi
##  Functions: check for a separate function file, and if we find one
##  source it.
if [[ -f "$Functions" ]];then . "$Functions";fi
##  enable programmable completion features (you don't need to enable
##  this, if it's already enabled in /etc/bash.bashrc and /etc/profile
##  sources /etc/bash.bashrc).
if [[  -f "$Completions" ]] && ! shopt -oq posix;then . "$Completions";fi
#
##  Function to run upon exit of shell.
function _exit()
{
  printf '%b\n' ${Cyan}"\tDobby lives only to serve MASTER!${Nc}"
  tput smcup
  clear
}
trap _exit EXIT

#export GPGKEY=YOURKEY1
#export ENCKEY=YOURKEY2
#export SIGKEY=YOURKEY3
## date +"%Y.%j_%m.%d_%V.%u_%H.%M.%S"
export tardate="$(date +"%F")"
##  Navigation.
export pgp="${HOME}/.gnupg"
export shell="${HOME}/.usr/bin"
export clip="${HOME}/Templates"
export dta="${HOME}/Downloads"
export docs="${HOME}/Documents"
export pdf="${HOME}/PDF"
export public="${HOME}/Public"
export ubuntu="${HOME}/Ubuntu One"
export pix="${HOME}/Pictures"
export music="${HOME}/Music"
export videos="${HOME}/Videos"
export rclocal="/etc/rc.local"
iprules="/etc/iptables.rules"
if [[ -f "$iprules" ]];then export iprules;fi
mediad="/media/disk"
if [[ -d "$mediad" ]];then export mediad;fi
#
##  I prefer to start my shell in a subfolder.
cd "$dta"
#

Back to top.

My “ ${HOME}/.aliases.sh ”:

##  To disable an 'alias', in this shell, either issue an 'unalias NAME',
##  or to disable on a per command basis: Put an '\' in front of your command.
##  A double '##' means explanation.
##  A single '#' either means: A single command, or a commented out command.
#  A standalone '#', like in this line means: Next codeblock/alias.
##  Spit out the current used environment,
##  and make it more intelligible by sorting it alphabetically first.
##  It's also a quick way for looking up a certain alias. ; )
##  Hit 'q' to exit less. ; )
alias env='env |sort -g|less'
#
## Navigation.
##  The following 2 conventions, totally depend on perspective. ; )
##  Personally I feel this to be more intuitive, than using 'p' the whole time.
##  'Previous' directory.
alias p='cd -'
##  'Next' directory.
alias n='cd -'
##  Go 'up' one directory.
alias up='cd ..'
##  Go 'up' two directories.
alias up2='cd ../../'
##  Go 'up' three directories.
alias up3='cd ../../../'
#
##	Useful remove, copy and replace aliases.
alias rm='printf "%b\n" "\tUh oh\x21\n\tJust put the \x27\x5c\x27 in front \
of the \x27rm\x27 command.\n\tAnd you should be good to go. \x3b\x2d\x29"'
#  · v - Explain what's being done.
#  · i - Interactive mode, ask before overwriting anything.
#  · u - Update/move only, if file is newer,
#        or doesn't exist on the receiving end.
#  · a - 'Archive' mode.
alias cp='cp -vaiu'
alias mv='mv -viu'
##  Remove an empty directory, and be 'verbose' about it.
alias rmdir='rmdir -pv'
##  Make a directory,
##  and create its siblings, if any.
alias mkdir='mkdir -pv'
#
##  File, and folder listings, miscellaneous settings.
##  Enable color support of ls and also add handy aliases
if [ "$TERM" != "dumb" ] && [ -x /usr/bin/dircolors ]; then
    eval "$(dircolors -b)"
    alias l='ls --color=auto'
    alias l.='ls -d  --color=auto .*'
    alias la='ls -a --color=auto'
    alias ll='ls -l --color=auto'
    alias ld='ls -d --color=auto */'
    alias lh='ls -lh --color=auto'
    alias lx='ls -X --color=auto'
    alias lha='ls -lha --color=auto'
    alias list='ls -lhtFG --group-directories-first --color=auto'
    alias rlist='ls -lrhtFG --group-directories-first --color=auto'
    alias dir='dir --color=auto -clth'
    alias grep='grep --color=auto'
    alias grepi='grep -i --color=auto'
    alias grepin='grep -in --color=auto'
    alias fgrep='fgrep --color=auto'
    alias egrep='egrep --color=auto'
fi
#
##	Enhance your calm John Spartan.
##	Replacement echo:
##  Also see: http://wiki.bash-hackers.org/commands/builtin/printf
##  A lot of scripts I've viewed online (including my own),
##  require or rely heavy on the 'echo' builtin.
##  The following alias makes sure,
##  everything remains 'backwards compatible'. ; )
##  This includes, and isn't limited,
##  to the \escapes I often use in my code. ; )
alias echo="printf '%b\n'"
##  The following will make 'printf' print out everything it's provided with,
##  in a LITERAL sense, it's also the preferred way of using 'printf',
##  as mentioned in the article above. ; )
#  alias printf="printf '%s\n'"
#
##  A quick and dirty way to show all hidden folders in your home directory,
##  or any other (you've 'rw(x)' permission(s) for). ; )
alias lhd='echo .{,*}/|tail -n +4|less'
##  Same as above, but do it for visible folders only.
##  Using 'v' here instead of expected 'l' for list.
##  The 'ld' alias from line 28 lists everything horizontally. ; )
##  Whereas 'vd' lists vertically. If the current folder is empty,
##  then a '*' appears in "less'" output.
##  Why use 'less' you say? Because it's 'more'. : )
##  Hit 'q' to exit less. ; )
alias vd='echo {,*}/|tail -n +2|less'
#
##	Disk usage.
alias du='du -sh|less'
##  '2>&-' ←  This effectively kills any output to 'stderr',
##  it's better than using '2>/dev/null' ; )
##  I've no need to be reminded of the following:
##  "df: `~/.gvfs': Transport endpoint is not connected"
##  I use 'ecryptfs', it might have something to do with that. : )
alias df='df -Th 2>&-|less'
#
##	Clear and reset the terminal in just one command.
alias cnr='clear && reset'
##	Or clear, reset terminal, and lock screen, all in one go.
alias lock='clear && reset && gnome-screensaver-command --lock'
#
##	Let's say: You've installed a new font in for example ~/.fonts \?
alias Newfont='sudo fc-cache -f -v'
#
##	My most common gzip usage.
alias gzip='gzip --best -v ' #	Name of file or files when using a loop.
#  gzip -c index.html.en > index.html.test.gz
#  gunzip -c type.cursus.html.gz > type.cursus.html
#
##	How to kill that annoying app.
##  Use: pgrep name to obtain its PID.
##  E.g.: pgrep firefox.
alias kill9='kill -s 9' #	PID DIE!
alias khup='kill -s 1' #	PID HUP
alias gkill='kill -USR1' #	PID Gently kill e.g. thttpd
alias kint='kill -s 2' #	PID Violently kill e.g. thttpd
#
##	wget usage.
##  Of course I could set all the following options,
##  in its own dedicated ~/.wgetrc.
##  Let's pretend we're a a generic tor-browser user. lol
##  E.g.:
##  "Mozilla/5.0 (Windows NT 6.1; rv:24.0) Gecko/20100101 Firefox/24.0"
##  Also see: https://www.torproject.org/download/download-easy.html.en
UAF="Mozilla/5.0 (Windows NT 6.1; rv:24.0) Gecko/20100101 Firefox/24.0"
RoBot="Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"
alias wget='wget -S --random-wait --user-agent="${UAF}" --progress=bar'
##  I know my ip-address doesn't match Google's,
##  but we're checking for the existence of a page.
##  I.e. We're doing a HEAD request, instead of a GET request.
##  Make sure to '\' escape the previous 'wget alias'. ; )
##  'set -x' revealed wget sending an 'user-agent' twice. lol
alias spider='\wget -S --user-agent="${RoBot}" --spider'
##  I've Tor functioning as 'a transparent proxy', on my box.
##  I may or may not, write a post about it later on?
alias Guy='sudo -u anonymous \wget -S --user-agent="${UAF}" --progress=bar'
##  Same here as 'spider' from up above, only we're doing it anonymously now.
alias Fawkes='sudo -u anonymous \wget -S --user-agent="${RoBot}" --spider'
#
##	Determine mimetype, and be brief about it.
##  Option '-L' causes symlinks to be followed, as the like-named option in 'ls'
##  (on systems that support symbolic links).
##  This is the default if the environment variable POSIXLY_CORRECT is defined.
alias file='file --mime-type -b'
alias encoding='file --mime-encoding -b'
#
##	Media related.
##  https://ffmpeg.org/trac/ffmpeg/wiki/UbuntuCompilationGuide
##	ffmpeg -version
alias ffv='ffmpeg 2>&1 | head -n1'
##	Shorthand for 'ffmpeg -i'
alias ffi='ffmpeg -i'
alias sdof='composite first.jpg -blend 30% -depth 30% last.jpg middle.jpg'
#
##	Enhanced copying.
#  · z - Compress the stream.
#  · h - Output in human readable format.
#  · H - Preserve Hard links, if any.
#  · a - 'Archive' mode.
#  · X - Preserve eXtended attributes, if any.
#  · v - Be verbose.
#  · u - Update.
#  · p - --partial || --progress.
#  · d - Delete before transfer.
#  · n - Dry run.
#  --remove-source-files #  Sender removes synchronized files (non-dir)
##  See 'man rsync' for more info on the matter.
alias rsync='rsync -vazh --progress'
alias usync='rsync -vazhu --progress'
alias dsync='rsync -vazh --progress --delete'
#	--exclude-from="${HOME}"/.exclude.txt
#
##	Most common firefox user agent: Mozilla/5.0
##  (Windows NT 6.1; WOW64; rv:23.0) Gecko/20100101 Firefox/23.0
##	Most common chrome user agent: Mozilla/5.0
##  (Windows NT 6.1; WOW64) AppleWebKit/537.36
##  (KHTML, like Gecko) Chrome/28.0.1500.95 Safari/537.36
#  UAC="Mozilla/5.0 \
#  (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) \
#  Chrome/28.0.1500.95 Safari/537.36"
#  alias chromium='chromium-browser --user-agent="${UAC}"'
#  alias chromium-black='chromium-browser --user-agent="${UAC}" \
#  --cipher-suite-blacklist=0x0005,0x0004'
#
##	Local folders.
alias Dta='cd ${dta}/ && rlist'
##	Here my 'bin' folder lives.
alias Shell='cd ${shell}/ && rlist'
##	The gnu, the gnu, the gnu.
alias Pgp='cd ${pgp}/ && rlist'
##	ubuntu one.
alias Ubuntu='cd "${ubuntu}"/ && rlist'
##	See the contents of, ~/.config/ , and /etc/xdg/user-dirs-defaults
##  Navigation.
##  Here I've put the standard paths in 'Ubuntu', my setup differs!
alias Clip='cd ${clip}/ && rlist'
alias Docs='cd ${docs}/ && rlist'
alias Pdf='cd ${pdf}/ && rlist'
alias Public='cd ${public}/ && rlist'
alias Pix='cd ${pix}/ && rlist'
alias Music='cd ${music}/ && rlist'
alias Videos='cd ${videos}/ && rlist'
##	flash specific.
alias Sys='cd /.macromedia/Flash_Player\
/macromedia.com/support/flashplayer/sys && rlist'
alias Shared='cd "${HOME}"/.macromedia/Flash_Player/#SharedObjects && rlist'
alias Vuurfox='cd "${HOME}"/.mozilla/firefox && rlist'
#alias cache='cd "${HOME}"/.mozilla/firefox/<8chars>.default/Cache && rlist'
##	Local non-home
alias Logs='cd /var/log && rlist'
alias Www='cd /var/www && rlist'
#
##	Macromedia flash specific
alias findsol='find -iname '*.sol' | wc -l'
alias printsol="find -iname '*.sol' -printf '%p\n'"
alias rmsol='find -iname '*.sol' -exec rm "{}" \;'
#
#Search and show available packages.
alias aptsearch='apt-cache search'
alias aptshow='apt-cache show'
#
##	Timestamp
#  alias dtouch='find . -type d -exec touch -t 201010100101.01 {} \;'
#  alias ftouch='find . -type f -exec touch -t 201010100101.01 {} \;'
#
##	Rights and ownership managment.
alias pfchmod='find . -type f -exec chmod 600 {} \;'
alias prchmod='find . -type f -exec chmod 400 {} \;'
alias pxchmod='find . -type f -exec chmod u+x {} \;'
alias puchmod='find . -type f -exec chmod u-x {} \;'
alias pdchmod='find . -type d -exec chmod 1700 {} \;'
alias gfchmod='find . -type f -exec chmod 640 {} \;'
alias gdchmod='find . -type d -exec chmod 1750 {} \;'
alias ofchmod='find . -type f -exec chmod 644 {} \;'
alias odchmod='find . -type d -exec chmod 755 {} \;'
alias mexec='chmod u+x'
alias uexec='chmod u-x'
alias ch2me='sudo chown 1000:1000 '
#  alias ch2you='sudo chown 1001:1001 '
##	Alternatives to the ones above.
#  The perl examples should be on ONE line!?
#  alias ch2normal="perl -MFile::Find -e \
#  'find sub { -f && chmod 0644, $_; -d && chmod 00755, $_ },"."'"
#  alias ch2sticky="perl -MFile::Find -e \
#  'find sub { -f && chmod 0644, $_; -d && chmod 01755, $_ },"."'"
#  alias ch2private="perl -MFile::Find -e \
#  'find sub { -f && chmod 0600, $_; -d && chmod 01700, $_ },"."'"
alias xargsf='find . -type f -print0 | xargs -0 chmod 644'
alias xargsd='find . -type d -print0 | xargs -0 chmod 1750'
#
##	Secure deletion tools.
#  alias Smem='sudo smem -v'
#  alias qdel='srm -lv'
#  alias qrdel='srm -lvr'
#  alias qhist='srm -lv "${HOME}"/.bash_history && touch "${HOME}"/.bash_history'
#
##	What have we logged today.
Syslog="/var/log/syslog"
alias ltcpo='grep -i denied\ outgoing\ tcp "${Syslog}"'
alias ludpo='grep -i denied\ outgoing\ udp "${Syslog}"'
alias licmpo='grep -i denied\ outgoing\ icmp "${Syslog}"'
alias ltcp='grep -i denied\ tcp "${Syslog}"'
alias ludp='grep -i denied\ udp "${Syslog}"'
alias licmp='grep -i denied\ icmp "${Syslog}"'
alias ltcp6='grep -i denied\ ipv6\ tcp "${Syslog}"'
alias ludp6='grep -i denied\ ipv6\ udp "${Syslog}"'
alias licmp6='grep -i denied\ ipv6\ icmp "${Syslog}"'
#
##	Firefox optimizations
#  alias optimzeff='killall firefox && \
#  find "${HOME}"/.mozilla/ \( -name "*.sqlite" \) \
#  -exec sqlite3  {} "vacuum" \;'
#  alias optdef='sqlite3 "${HOME}"/.mozilla/firefox/\
#  abcd1234.default/places.sqlite "vacuum"'
#
##	Show my open connections
alias lsofu='lsof -i -n -P'
#
##	Comes out as: Dow, Month Day, Year
##	e.g.: Saturday, July 21, 2012
alias todayis='date +"%A, %B %-d, %Y"'
#
##  Nano.
alias nano='nano -Amu'
#
##	Imagemagick
alias identify='identify -verbose'
#
#  For 'cryptographic' purposes.
alias randkey='head -c 48 /dev/urandom | openssl enc -base64'
#
###############################################################################
##	aliases that Require Root privileges!
#
##	Keeping the system up to date
alias Aptall='sudo apt-get update && sudo apt-get -y upgrade \
&& sudo apt-get autoclean && sudo apt-get autoremove'
alias Update='echo "sudo apt-get update " && sudo apt-get update'
alias Upgrade='echo "sudo apt-get upgrade " && sudo apt-get upgrade'
alias Autoclean='echo "sudo apt-get autoclean " && sudo apt-get autoclean'
alias Clean='echo "sudo apt-get clean " && sudo apt-get clean'
alias Autoremove='echo "sudo apt-get autoremove " && sudo apt-get autoremove'
alias Remove='echo "sudo apt-get remove " && sudo apt-get remove'
alias Purge='echo "sudo apt-get purge " && sudo apt-get purge'
alias Install='echo "sudo apt-get install " && sudo apt-get install'
alias Simulate='echo "sudo apt-get install -s" && sudo apt-get install -s'
alias Aptlist='sudo dpkg --get-selections >"${ubuntu}"/Shared/Precise.Pangolin.\
dpkg.lists/Precise.Pangolin."$(date +"%F")".dpkglist.txt'
alias Sign='crypto -s "${ubuntu}"/Shared/Precise.Pangolin.dpkg.lists/\
Precise.Pangolin."$(date +"%F")".dpkglist.txt'
alias Etcapt='sudo tar cvpfJ etc.apt."$(date +"%F")".txz \
/etc/apt/ && mv etc.apt.*.txz "${ubuntu}"/Shared/Precise.Pangolin.dpkg.lists/'
#
##	List firewall rules.
alias Arptables='sudo arptables -L -n -v'
alias Ip6tables='sudo ip6tables -L -n -v --line-numbers'
alias Iptables='sudo iptables -L -n -v --line-numbers'
#
##	Did we already block this ip before\?
#  alias checkip='cat /etc/iptables.rules | grep'
#
##	Block a single Ip-address.
#	E.g.: BlIp 1.2.3.4
#  alias Blip='sudo iptables -I blacklist 1 \
#  -j REJECT --reject-with icmp-host-prohibited -s'
##	Block 'whole net'.
##	E.g.: BlNet 1.2.3.0/24
#  alias Blnet='sudo iptables -I blacklist 1 \
#  -j REJECT --reject-with icmp-net-prohibited -s'
##	This one deletes a rule
#  iptables -D blacklist <rulenr>
#
##	Show open connections from other users.
alias Lsofb='sudo -u boinc lsof -i -n -P'
alias Lsofo='sudo -u onion lsof -i -n -P'
alias Lsofdt='sudo -u debian-tor lsof -i -n -P'
alias Lsofa='sudo lsof -i -n -P'
#
#	Extended filesystem permissions.
alias Immutable='sudo chattr +i'
alias Unmute='sudo chattr -i'
alias lsattr='lsattr -v'
alias ldattr='lsattr -vd'
##	Mount helpers
#
alias Bind='sudo mount -o bind' #	/sourcefolderurl /destinationfolderurl
alias Iso='sudo mount -o loop' #	/path/to/iso /media/iso/name_of_folder
alias Umount='sudo umount' #	/destinationfolderurl
##	Example
#alias Bsd='sudo mount -o loop /boot/PCBSD9.1-x64-DVD.iso /media/iso/PC-BSD/'
#alias Tame='sudo umount /media/iso/PC-BSD/'
#
##  Chromium specific, make the browser faster by storing its cache into ram.
##  To issue, BEFORE you start up 'chromium', of course. ; )
Ccache="${HOME}/.cache/chromium/Default/Cache"
alias Mcache='sudo mount -t tmpfs \
-o size=512M,defaults,rw,nosuid,nodev tmpfs \
"${Ccache}"'
##  Don't forget to 'umount' your cache before loggin out. ; )
alias Dcache='sudo umount "${Ccache}"'
#
##	[S]start|[K]stop|[U]status service(s)
alias Sboinc='sudo service boinc-client start'
alias Kboinc='sudo service boinc-client stop'
alias Uboinc='sudo service boinc-client status' #	Update/Status
#
##  Miscellaneous:
##	embraceubuntu.com/2005/09/07/adding-a-startup-script-to-be-run-at-bootup/
##	Creating Daemons that start and stop on both system start and stop.
##	Create:
#  /etc/init.d/FOO
##	Then:
#  update-rc.d FOO defaults
##	Or for a 'dry' run (note the -n switch):
#  update-rc.d -n FOO defaults
##	Finally do:
#  chmod +x FOO
#

Back to top.

“ My “${HOME}”/.functions.sh ”:

##	Mandatory 'root' check ; )
##	Yes, you may disable this check, but ... I put it in here, for good reason.
##	You are hereby warned. ; )
if [ "$UID" = "0" ];then
  printf '%b\n' "\tError: \"${USER}\" isn't allowed to use \"YOUR\" bash functions."
  printf '%b\n' "\tUse \"sudo -i\" instead, for \"admin\" purposes. \x3b\x2d\x29"
  exit 1
else
  ##  -------------------------------------------------------------
  ##  Greeting, motd etc...
  ##  -------------------------------------------------------------
  ##  Define some colors first:
  ##  30=black 31=red 32=green 33=yellow 34=blue 35=magenta 36=cyan 37=white
  ##  Also see: http://wiki.bash-hackers.org/scripting/terminalcodes
  export Black="\033[0;30m"
  export Red="\033[0;31m"
  export Green="\033[0;32m"
  export Yellow="\033[1;33m"
  export Blue="\033[1;34m"
  export Magenta="\033[1;35m"
  export Cyan="\033[1;36m"
  export White="\033[1;37m"
  export Nc="\033[0m" #	No Color
  ##  --> Nice. Has the same effect as using "ansi.sys" in DOS.
  llength="80"
  printf -v line '%*s' "$llength"
  line="${line// /-}"
  printf '%b\n' "$line"
  printf '%b\n' "\t     _/  _/    _/                            _/    "
  printf '%b\n' "\t  _/_/_/_/_/  _/_/_/      _/_/_/    _/_/_/  _/_/_/ "
  printf '%b\n' "\t   _/  _/    _/    _/  _/    _/  _/_/      _/    _/"
  printf '%b\n' "\t_/_/_/_/_/  _/    _/  _/    _/      _/_/  _/    _/ "
  printf '%b\n' "\t _/  _/    _/_/_/      _/_/_/  _/_/_/    _/    _/  \n"
  printf '%b\n' "$line"
  printf '%b\n' "\t\u201cOh, what a tangled web we weave \
when first we practise to deceive.\u201d\n"
  printf '%b\n' "$line"
  ##  I escape my used 'smileys',
  ##  because this or that blog may interpret them as such. ; )
  ##  Thus '\x3a\x2d\x29' prints as ': )', plus the dash.
  ##  And '\x3b\x2d\x29' prints as '; )', plus the dash.
  printf '%b\n' "\tWelcome \u201c${USER^}.\u201d \x3a\x2d\x29\n"
  printf '%b\n' "\tYou may proceed.\n\tMay \u262E be with you.\n"
  printf '%b\n' "$line"
  ##  Every itself-respecting *nix, should have this tool. : )
  ##  Thus this test is 'redundant'.
  Which="/usr/bin/which"
  if
    [[ -x "$Which" ]]
  then
    filetype()
    {
    ##  As the program 'file' previously got defined as:
    ##  'file --mime-type -b' in our '~/.aliases.sh' file,
    ##  we can now directly reference it here. ; )
    if
      [[ -f "$1" ]]
    then
      filetype=$(file "$1"|awk -F'/' '{print $2}')
      printf '%b\n' ${Blue}""$filetype""${Nc}
    else
      [[ -d "$1" ]]
      printf '%b\n' ${Yellow}"\tThis is a folder/directory. \x3a\x2d\x44"${Nc}
    fi
    }
    ztar()
    {
    if
      [[ -x "$(which tar)" ]]
    then
      Usage()
      {
        printf '%b\n' ${Yellow}"\tUsage:"${Nc}
	      printf '%b\n' "\t"${FUNCNAME[1]}" yourfile.ext"
	      printf '%b\n' "\t"${FUNCNAME[1]}" yourfolder/"
      }
    ##	Uncomment, if not defined in bashrc
    #tardate="$(date +"%F")"
    #printf '%b\n' "\t${0##*/}"
      if
        [[ -z "$1" ]]
      then
        Usage
      elif
        [[ -d "$1" ]]
      then
        tar cvpfJ "${1%/*}.$tardate.txz" "$1"
      elif
        [[ -f "$1" ]]
      then
        tar cvpfJ "${1%.*}.$tardate.txz" "$1"
      fi
    fi
    }
    utar()
    {
    if
      [[ -x "$(which tar)" ]]
    then
      Usage()
      {
        printf '%b\n' ${Yellow}"\tUsage:"${Nc}
	      printf '%b\n' "\t"${FUNCNAME[1]}" yourfile.{txz,tgz,tbz}"
      }
      if
        [[ -z "$1" ]]
      then
        Usage
      else
        [[ -f "$1" ]]
        filetype=$(file "$1"|awk -F'/' '{print $2}')
        case "$filetype" in
        "x-gzip")
        tar xvpfz "$1"
        ;;
        "x-bzip2")
        tar xvpfj "$1"
        ;;
        "x-xz")
        tar xvpfJ "$1"
        ;;
        *)
        printf '%b\n' ${Yellow}"\tThis isn't a tar-archive!"${Nc}
        printf '%b\n' ${Yellow}"\tFile type:${Nc} ${Blue}"$filetype""${Nc}
        ;;
        esac
      fi
    fi
    }
    create.m3u()
    {
    if
      [[ -z "$1" ]]
    then
      printf '%b' "\tEnter name for output file: "
      read Arg
    else
      Arg="$1"
    fi
    ##	The following line makes certain you can type a 'normal' sentence as filename.
    ##	All this without 'violating' UNIX' restriction on spaces.
    ##	I.e. 'This is my recording' becomes 'This.is.my.recording'
    printf '%b\n'
    Arg="${Arg//\ /.}"
    ##  Let's capitalize your sentence, just in case you forgot. : )
    Arg="${Arg^}"
    Arg+=".m3u"
    printf '%b\n' "#EXTM3U" > "$Arg"
    find -iname '*.og*' -printf '%p\n'|sort -g>>"$Arg"
    find -iname '*.mp*' -printf '%p\n'|sort -g>>"$Arg"
    find -iname '*.wma' -printf '%p\n'|sort -g>>"$Arg"
    find -iname '*.flv' -printf '%p\n'|sort -g>>"$Arg"
    find -iname '*.f4*' -printf '%p\n'|sort -g>>"$Arg"
    find -iname '*.m4*' -printf '%p\n'|sort -g>>"$Arg"
    find -iname '*.avi' -printf '%p\n'|sort -g>>"$Arg"
    find -iname '*.mkv' -printf '%p\n'|sort -g>>"$Arg"
    find -iname '*.wmv' -printf '%p\n'|sort -g>>"$Arg"
    find -iname '*.pls' -printf '%p\n'|sort -g>>"$Arg"
    ##  Be a good boy, clean up after you're done. : )
    unset Arg
    }
    ##	Configure flash data/player.
    conf.sol()
    {
    clear
    sys="${HOME}/.macromedia/Flash_Player/macromedia.com/support/flashplayer/sys"
    shared="${HOME}/.macromedia/Flash_Player/#SharedObjects"
    ##  For those on google-chrome, you might want to uncomment the following 2 lines!?
    ##  And the ones referred to in the function below.
    #gchromesys="${HOME}/.config/google-chrome/Default/Pepper Data/\
    #Shockwave Flash/WritableRoot/macromedia.com/support/flashplayer/sys"
    #gchromeshared="${HOME}/.config/google-chrome/Default/Pepper Data/\
    #Shockwave Flash/WritableRoot/#SharedObjects"
    Usage()
    {
      printf '%b\n' ${Yellow}"\tUsage:"${Nc}
	    printf '%b\n' "\t"${FUNCNAME[1]}" --disallow or -n"
	    printf '%b\n' "\t"${FUNCNAME[1]}" --allow or -y"
	    printf '%b\n' "\t"${FUNCNAME[1]}" --reset or -r"
    }
    if
      [[ -z "$1" ]]
    then
      Usage
    else
      case "$1" in
      "--allow" | "-y")
      chmod -c 0750 "$shared"/ "$sys"/ #	"$gchromeshared"/ "$gchromesys"/
      ;;
      "--disallow" | "-n")
        if
          [[ -w "$sys" ]]
        then
          ##  2>/dev/null and 2>&- function the same, the latter 'closes' it.
          ##  FD? acron. for: File-descriptor.
          ##  So what does it do?
          ##  It causes 'error-messages', to be completely ignored/cut off.
          ##  Useful, when you already know 'this or that' file might not exist,
          ##  but you need to do, whatever it is, it anyway. ; )
          \rm -r "${sys}"/\#* 2>&-
          \rm -r "${shared}"/* 2>&-
          #  \rm -r "${gchromesys}"/\#* 2>&-
          #  \rm -r "${gchromeshared}"/* 2>&-
          chmod -c 0500 "$shared"/ "$sys"/ #	"$gchromeshared"/ "$gchromesys"/
        else
          printf '%b\n' ${Yellow}"\tNo write permission granted.\n\
          \n\tPlease use the${Nc} '${Blue}allow${Nc}'${Yellow} option first, \
          if you wish to purge all flash data\x21"${Nc}
        fi
      ;;
      "--reset" | "-r")
        if
          [[ -w "$sys" ]]
        then
          \rm -r "${sys}"/\#* 2>&-
          \rm -r "${shared}"/* 2>&-
          #  \rm -r "${gchromesys}"/\#* 2>&-
          #  \rm -r "${gchromeshared}"/* 2>&-
        else
          printf '%b\n' ${Yellow}"\tNo write permission granted."${Nc}
        fi
      ;;
      *)
      Usage
      ;;
      esac
    fi
    unset sys shared
    }
    ## Tidy up any html file with 'tidy'
    mtidy()
    {
    clear
    if
      [[ -x "$(which tidy)" ]]
    then
      Usage()
      {
        printf '%b\n' ${Yellow}"\tUsage:"${Nc}
	      printf '%b\n' "\t"${FUNCNAME[1]}" -f yourfile.html"
	      printf '%b\n' "\t"${FUNCNAME[1]}" -d yourfolder/"
      }
      if
        [[ -z "$1" ]];
      then
        Usage
      else
        if
          [[ ! -d "${HOME}/.usr/etc" ]]
        then
          mkdir -p "${HOME}"/.usr/etc
        fi
        config="${HOME}/.usr/etc/config.txt"
        if
          [[ ! -f "$config" ]]
        then
cat >>"$config"<<_EOF_
// sample config file for HTML tidy
doctype: transitional
indent: auto
indent-spaces: 2
wrap: 76
markup: yes
bare: yes
clean: yes
preserve-entities: yes
output-xml: no
input-xml: no
output-xhtml: yes
show-warnings: yes
numeric-entities: yes
quote-marks: yes
quote-nbsp: yes
quote-ampersand: no
break-before-br: no
uppercase-tags: no
uppercase-attributes: no
char-encoding: utf8
input-encoding: utf8
output-bom: auto
output-encoding: utf8
new-inline-tags: cfif, cfelse, math, mroot,
  mrow, mi, mn, mo, msqrt, mfrac, msubsup, munderover,
  munder, mover, mmultiscripts, msup, msub, mtext,
  mprescripts, mtable, mtr, mtd, mth
new-blocklevel-tags: cfoutput, cfquery
new-empty-tags: cfelse
repeated-attributes: keep-last
error-file: errs.txt
write-back: yes
_EOF_
        fi
        case "$1" in
        "--file" | "-f")
        if [ -z "$2" ];then
         Usage
        else
        ##	Just make sure, we're really dealing with a 'text/html' file here.
          filetype=$(file "$2"|awk -F'/' '{print $2}')
          if
            [[ "$filetype" = "html" ]]
          then
            tidy -config $config "$2"
            \rm errs.txt
          else
            Usage
          fi
        fi
        ;;
        "--folder" | "-d")
        find -iname '*.html' -exec tidy -config "$config" '{}' \;
        ;;
        *)
        Usage
        ;;
        esac
      fi
    unset filetype config
    fi
    }
    link()
    {
    clear
    ##	Link files that reside in the same folder or below.
    ##	Useful for chrooted environments.
    URLENc=$(printf '%b\n' "$1" | sed -e "s_%20_\\ _g")
    if
      [[ -n "${URLENc}" ]]
    then
      Arg=${URLENc/file:\/\//};else Arg="${Arg}"
    fi
    MOVED=$(printf '%b\n' "${Arg}" | sed -e "s_\\ _._g")
    if
      [[ -f "${MOVED}" ]]
    then
      Arg="${Arg}"
    else mv "${Arg}" "${MOVED}" 2>&-
      Arg=${MOVED}
    fi
    ln -s -T "$Arg" "$2" #	target  name
    ##  Special link case: How to link multiple folders.
    ##  i.e. $Target, to same named $Name
    #  cd /path/to/folder/
    #  alias ld='ls -d --color=auto */'
    #  ld >dir.txt
    #  cat dir.txt | while read line;
    #  do;
    #  Target=$(printf '%b\n' "/media/my-movies/${line}");
    #  Name=$(printf '%b\n' "/home/alexander/Videos/Movies/${line%\/}");
    #  ln -s -T "$Target" "$Name";
    #  done
    #  \rm dir.txt
    unset Arg MOVED URLENc
    }
    ##  Rip to the aac_he codec.
    m4a()
    {
    clear
    if
##    Debian => Ubuntu => Linux Mint users, might find the following useful:
##    https://trac.ffmpeg.org/wiki/UbuntuCompilationGuide
      [[ -x "$(which ffmpeg)" ]]
    then
      Usage()
      {
        printf '%b\n' ${Yellow}"\tUsage:"${Nc}
	      printf '%b\n' "\t"${FUNCNAME[1]}" yourfile.wav"
      }
      if
        [[ -z "$1" ]]
      then
        Usage
      else
      filetype="$(file --mime-type -b "$1"|awk -F'/' '{print $2}')"
        if
          [[ "$filetype" = "x-wav" ]] || [[ "$filetype" = "x-flac" ]]
        then
          Arg="$1"
          Out="${Arg^}"
          Out="${Out%.*}.m4a"
          Title="Yet another fine recording, by yours truly."
          Album="Desktop Recordings."
          Date="$(date +"%A, %B %-d, %Y")"
          Copy="Attribution 3.0 Unported (CC BY 3.0)"
          Quote="Without music, life would be a mistake. ~Nietzsche"
          ffmpeg -i "$Arg" \
          -c:a libfdk_aac \
          -profile:a aac_he \
          -b:a 128000 \
          -ac 2 \
          -metadata title="$Title" \
          -metadata artist="${USER^}" \
          -metadata album="$Album" \
          -metadata genre="DIY" \
          -metadata track="1/1" \
          -metadata date="$Date" \
          -metadata copyright="$Copy" \
          -metadata comment="$Quote" \
          "$Out"
#          \rm "$Arg"
          unset Arg Out filetype Title Album Date Copy Quote
        fi
      fi
    fi
    }
    ##	Rip from wav to ogg.
    ogg()
    {
    clear
    if
      [[ -x "$(which oggenc)" ]]
    then
      Usage()
      {
        printf '%b\n' ${Yellow}"\tUsage:"${Nc}
	      printf '%b\n' "\t"${FUNCNAME[1]}" yourfile.wav"
      }
      if
        [[ -z "$1" ]]
      then
        Usage
      else
      filetype="$(file --mime-type -b "$1"|awk -F'/' '{print $2}')"
        if
          [[ "$filetype" = "x-wav" ]] || [[ "$filetype" = "x-flac" ]]
        then
          Arg="$1"
          Out="${Arg^}"
          Out="${Out%.wav}.ogg"
          Title="Yet another fine recording, by yours truly."
          Album="Desktop Recordings."
          Date="$(date +"%A, %B %-d, %Y")"
          Copy="Attribution 3.0 Unported (CC BY 3.0)"
          Quote="Without music, life would be a mistake. ~Nietzsche"
          oggenc -q 5 \
          "$Arg" \
          -t "$Title" \
          -a "${USER^}" \
          -d "$Date" \
          -l "$Album" \
          -G "DIY" \
          -c "Publisher=E.L.F." \
          -c "Quote=$Quote" \
          -c "Copyleft=$Copy" \
          -o "$Out"
#          \rm "$Arg"
          unset Arg Out filetype Title Album Date Copy Quote
        fi
      fi
    fi
    }
    mknfo()
    {
    clear
    if
    ##  Debian => Ubuntu => Linux Mint users, might find the following useful:
    ##  https://trac.ffmpeg.org/wiki/UbuntuCompilationGuide
      [[ -x "$(which ffmpeg)" ]]
    then
      Usage()
      {
        printf '%b\n' ${Yellow}"\tUsage:"${Nc}
	      printf '%b\n' "\t"${FUNCNAME[1]}" yourfile"
      }
      if
        [[ -z "$1" ]]
      then
        Usage
      else
        filetype="$(file --mime-type -b "$1"|awk -F'/' '{print $2}')"
        mediatype="$(file --mime-type -b "$1"|awk -F'/' '{print $1}')"
        Arg="$1"
        ##  Because this script detects 'vorbis/theora', and 'matroska' files,
        ##  as 'application/ogg' or 'application/octet-stream' respectively.
        ##  Not very useful, if you ask me. *ugghhh*
        ##  Hence the following case, to determine the proper mimetype,
        ##  by using its extension. It's ugly, I know.
        ##  Let's test it first, and move on, if nothing found.
        if
          [[ "application" = "$mediatype" ]]
        then
        ##  Sure we could use "${Arg##*.}",
        ##  to determine the extension of the filename. ; )
        ##  And "${Arg##*/}" to strip off the path,
        ##  and be left with the 'filename'. ; )
        ##  But we won't, since we prefer to recycle code, not add to it.
          case "$filetype" in
          "ogm" | "ogv" | "mkv" )
          mediatype="video"
          ;;
          ## The 'ogg' extension can still contain both audio and video.
          "ogg" | "oga" | "mka" )
          mediatype="audio"
          ;;
          *)
          ;;
          esac
        fi
        ##  Here we format the output.
        ##  Get its path.
        Path="${Arg%/*}"
        ##  What's the file's name.
        File=""${Arg##*/}""
        ##  We don't want to screw up the user's path here. ; )
        Out="${File^}"
        ##  Let's put the 'nfo' file in the same folder,
        ##  as where we found 'File'.
        ##  Adding a little test here first, because of erroneous errors.
        ##  Caused, by working in the same folder as where the file is located. 
        if
          [[ "$Path" = "$File" ]]
        then
          Out="${Out%.*}.nfo"
        else
          Out="$Path"/"${Out%.*}.nfo"
        fi
        Tmp="$(mktemp)"
        ##  Here we test, if we're dealing with,
        ##  either a 'video', sound, or a still image.
        case "$mediatype" in
        "audio" | "video" )
        ffi "$Arg" 2>&1|tail -n +12|head -n -1>"$Out"
        cat "$Out"
        ##  Since 'nfo' files are usually 'windows' specific creatures. : D
        ##  Let's convert the 'nfo' file into that format.
        if
          ##  I shall leave nothing up to chance! ; )
          [[ -x "$(which unix2dos)" ]] && [[ -x "$(which iconv)" ]]
        then
        unix2dos < "$Out" | iconv -f UTF-8 -t UTF-8 > "$Tmp"
        \mv "$Tmp" "$Out"
        fi
        ;;
        "image" )
        if
          ##  Again I shall leave nothing up to chance! ; )
          [[ -x "$(which identify)" ]]
        then
          identify "$Arg"
        fi
        ;;
        *)
        printf '%b\n' ${Yellow}"\tThis isn't a media-file!"${Nc}
        printf '%b\n' ${Yellow}"\tFile type:${Nc} ${Blue}"$filetype""${Nc}
        ;;
        esac
        unset Arg Path File Out Tmp filetype mediatype
      fi
    fi
    ##  The following will run the above 'mknfo' function,
    ##  on all files found with for example the 'm4v' extension. ; )
    ##  You probably won't need to run 'sort -g' to sort it out,
    ##  but it makes the resulting file more readable,
    ##  just in case you're keeping it around for future reference.
    #  find -iname '*.m4*' -printf '%p\n'|sort -g>m4v.txt
    #  cat m4v.txt |while read line;do mknfo "$(echo ${line})"; done
    #  \rm m4v.txt
    }
    ##	This function will simulate the effect
    ##  the "mod_deflate" module for Apache has, for the same named files.
    ##	Only to be used with a server who understands the .gz format,
    ##  out of the box: E.g. thttpd
    ##	Also works in a chroot'ed environment. ; - )
    massedit()
    {
    #  filetype="$(file --mime-type -b "$1"|awk -F'/' '{print $2}')"
    #  mediatype="$(file --mime-type -b "$1"|awk -F'/' '{print $1}')"
    #  Arg="$1"
    #  case "$mediatype" in
    #  "text" )
    #  gzip --best -v "$Arg"
    #  ln -s -T "$Arg".gz "$Arg"
    #  ;;
    #  *)
    #  printf '%b\n' ${Yellow}"\These aren't text-files!"${Nc}
    #  printf '%b\n' ${Yellow}"\tFile type:${Nc} ${Blue}"$filetype""${Nc}
    #  ;;
    #  esac
    clear
    for files in *.{css,js,html,txt,xml,doc,odt,pdf}
    do
      if
        [ -f "$files" ]
      then
        gzip --best -v "$files"
        ln -s -T "$files".gz "$files"
      fi
    done
    unset files
    }
    ##	This one removes the empty lines and unnecessary spaces,
    ##	of the text based type of file,
    ##	you gave it to chew on. ; - )
    squeeze()
    {
    Usage()
    {
      printf '%b\n' ${Yellow}"\tUsage:"${Nc}
	    printf '%b\n' "\t"${FUNCNAME[1]}" yourfile"
    }
    clear
    if
      [[ -z "$1" ]]
    then
      Usage
    else
      [[ -f "$1" ]]
      mediatype="$(file --mime-type -b "$1"|awk -F'/' '{print $1}')"
      if
        [[ "text" = "$mediatype" ]]
      then
        sed -e '/^$/d' -e 's/[ \t]*$//' -i "$1"
      fi
      unset mediatype
    fi
    }
    crypto()
    {
    clear
    if
      [[ -x "$(which openssl)" ]] && [[ -x "$(which gpg)" ]]
    then
      Usage()
      {
        printf '%b\n' ${Yellow}"\tUsage:"${Nc}
	      printf '%b\n' "\tTo encrypt:\t"${FUNCNAME[1]}" -e yourfile"
	      printf '%b\n' "\tTo decrypt:\t"${FUNCNAME[1]}" -d yourfile.aes"
	      printf '%b\n' "\tTo sign:\t"${FUNCNAME[1]}" -s yourfile"
	      printf '%b\n' "\tTo verify:\t"${FUNCNAME[1]}" -v yourfile.asc"
      }
      Notify()
      {
      printf '%b\n' ${Yellow}"\tThere's no need to encrypt your file twice."${Nc} >&2
      printf '%b\n' ${Yellow}"\tYou could consider installing \u201cccrypt\x3f\u201d\n"${Nc} >&2
      printf '%b\n' ${Blue}"\tsudo apt-get install ccrypt\n"${Nc} >&2
      if
        [[ -x "$(which apt-cache)" ]]
      then
        printf '%b\n' ${Cyan}"\tRetrieving info about \u201cccrypt\u201d\n"${Nc} >&2
        sleep 1
        apt-cache show ccrypt
      fi
      }
      if
        [[ -z "$2" ]]
      then
        Usage
      elif
        [[ -d "$2" ]]
      then
        Usage
      else
        filetype="$(file --mime-type -b "$2"|awk -F'/' '{print $2}')"
        signature="pgp-signature"
        case "$1" in
        #	head -c 48 /dev/urandom | openssl enc -base64 #	&lt;- For better entropy.
        ##	All are alternatives to the one above.
        #	printf '%b\n' "Password"| openssl dgst -whirlpool|awk -F '= ' '{print $2}'
        #	printf '%b\n' "Password"| openssl dgst -whirlpool|awk -F '= ' '{print $2}'|base64 -w0
        #	cat text.txt| openssl dgst -whirlpool|awk -F '= ' '{print $2}'
        ##	Default cipher.
        #	aes-256-cbc
        "--encrypt" | "-e")
        if
          [[ ! "aes" = "${2##*.}" ]]
        then
        ##	Create a good strong pass{phrase,word} and store it in a 'hidden' file.
        ##	The goal would be to pass along your message over one channel. E.g.: email
        ##	And your $pphrase over another. E.g.: text
        #
        ##	Or use openpgp http://www.openpgp.org/
        ##	Also take a look here: http://ubuntuforums.org/showthread.php?t=939545
        head -c 48 /dev/urandom | openssl enc -base64 > ."${2%.*}".txt
        pfile=""$PWD"/."${2%.*}".txt"
        ##	Define it, so openssl knows where to look.
        pphrase="file://"${pfile}""
        ##	Now encrypt your file/any file with the aforementioned $pphrase.
        ##	Its output will be a 'readable' text file.
        #
        ##	Here I use the camellia cipher, but you are free to choose another of course!
        ##	http://www.madboa.com/geek/openssl/
        openssl camellia-256-cbc -a -e -salt -in "$2" -out "$2".aes -pass "$pphrase"
        ##	Also have a look at 'ccrypt' : http://ccrypt.sourceforge.net/
        ##	Make it 'read only', sending it to someone over mail, should fix the perms.
        chmod 400 "$2".aes
        ##	This file should only have +rw perms for the owner.
        ##	PS: Do NOT rename this file!
        chmod 600 "${pphrase/file:\/\//}"
        ##	Optional!
        ##	Just remember, if you lose your $pphrase, then it's GONE 4ever!
        \rm "$2"
        ##	There's no need to 'export' or to make it available to your env.
        unset pphrase
        elif
          [[ "aes" = "${2##*.}" ]]
        then
          Notify
        fi
        unset pfile
        ;;
        "--decrypt" | "-d")
        pfile=""$PWD"/."${2%.*.aes}".txt"
        if
        ##  If '$2' is a file, and is encrypted, do
          [[ "aes" = "${2##*.}" ]] && [[ -f "$pfile" ]]
        then
          pphrase="file://"${pfile}""
          openssl camellia-256-cbc -a -d -salt -in "$2" -out "${2%.aes}" -pass "$pphrase"
          chmod 600 "${2%.aes}"
          unset pphrase pfile
        else
          printf '%b\n' ${Yellow}"\tEither your file wasn't encrypted, or \
your key is lost\x3f"${Nc}
        fi
        unset pfile
        ;;
        "--sign" | "-s")
        ##	to sign (-s):
        if
          [[ ! "$signature" = "$filetype" ]]
        then
          printf '%b\n' ${Cyan}"\tgpg -a --detach-sign \""$2"\""${Nc}
          gpg -a --detach-sign "$2"
        else
          Usage
        fi
        ;;
        "--verify" | "-v")
        ##	to verify (-v):
        if
          [[ "$signature" = "$filetype" ]]
        then
          printf '%b\n' ${Cyan}"\tgpg --verify \""$2"\" \"${2%.asc}\""${Nc}
          gpg --verify "$2" "${2%.asc}"
        else
          Usage
        fi
        ;;
        *)
        Usage
        ;;
        esac
      unset filetype signature
      fi
    fi
    }
    png2pdf()
    {
    clear
    if
      [[ -x "$(which convert)" ]]
    then
      convert *.png -quality 100 Out.pdf
    fi
    }
    pdf2png()
    {
    clear
    if
      [[ -x "$(which convert)" ]]
    then
    for pdf in *.{pdf,pdf.gz}
    do
      convert -set -units PixelsPerCentimeter -density 120x120 -quality 90 $pdf ${pdf%.*}.png 2>&-
    done
    fi
    }
    strip()
    {
    ##	♪ ♫ Here's a little mod_rewrite I wrote. ♫ ♪ You might want to sing it ♪ for ♪ ...
    clear
    Arg="$1"
    if
      [[ -z "$1" ]]
    then
      printf '%b\n' ${Blue}"\t(Hit \"${Yellow}ctrl+shift+v${Blue}\" to paste.)"${Nc}
      printf '%b' ${Yellow}"\tPlease enter your url: "${Nc}
      read Arg
        if
          [[ -z "$Arg" ]]
        then
          printf '%b\n' ${Red}"\tPlease provide me with a string to work on."${Nc}
        else
          if
            [[ -n "$Arg" ]]
          then
            Arg="$Arg"
          fi
        fi
    fi
    if
      [[ -n $1 ]]
    then
      Arg="$1"
    fi
    FB="$(printf '%b\n' "$Arg" |grep 'facebook.com')"
    if
      [[ "$?" = "0" ]]
    then
      Arg="${Arg#*?u=}"
      Arg="${Arg%%\%3Fref*}"
      Arg="${Arg%%\&h=*}"
      Arg="${Arg%%\?fb*}"
      Color="${Red}"
    fi
    GG="$(printf '%b\n' "$Arg" |grep 'google.')"
    if
      [[ "$?" = "0" ]]
    then
      Arg="${Arg#*\&*url=}"
      Arg="${Arg%%\&ei=*}"
      Color="${Yellow}"
    fi
    YH="$(printf '%b\n' "$Arg" |grep 'yahoo.')"
    if
      [[ "$?" = "0" ]]
    then
      Arg="${Arg#*\/RU=}"
      Arg="${Arg%RS=*}"
      Color="${Blue}"
    fi
    #
    ##  And then…
    ##  We clean up after them.
    #
    ##  Remove the “&utm_” bollocks.
    ##  I want clean urls\x21
    Arg="${Arg%%\%26utm*}"
    ##  Let’s turn all those “ugly” hex characters into normal readable ones.
    Arg="${Arg//\%/\\x}"
    ##  Facebook specific.
    Arg="${Arg%%\?og*}"
    Arg="${Arg%%\?fb*}"
    ##  Youtube is a special case.
    YT="$(printf '%b\n' "$Arg" |grep 'youtube.com')"
    if [[ "$?" = "0" ]]
    then
    ##  Change to https://youtu.be/RXoH3_yL1ng, where the last 11 characters refer to the 'watch?v=RXoH3_yL1ng' part.
    Watch="${Arg#*?v=}"
    Watch="${Watch%%\&*}"
    Arg="https://youtu.be/"$Watch""
    Color="${Cyan}"
    fi
    ##  Eventually I’ll write out more url shorterner services.
      ##	tinyurl
      #	wget http://preview.tinyurl.com/2tqueo
      #	Item=$(grep 'redirecturl' 2tqueo)
      #	Item=$(printf '%b\n' "$Item" | sed -e 's_\(.*\)href="__')
      #	Url=$(printf '%b\n' "$Item" | sed -e 's_">\(.*\)__')
    ##  For now, this will do fine. http://bit.ly/QtQET+
    BL="$(printf '%b\n' "$Arg" |grep 'bit.ly')" || BL="$(printf '%b\n' "$Arg" |grep 'bitly.com')"
    if [[ "$?" = "0" ]]
    then
      Arg="${Arg/http/https}"
      Arg="${Arg/bit.ly/bitly.com}"
      Color="${White}"
      wget "$Arg+"
      Arg="$(grep 'bitmark_long_url' *+)"
      Arg="${Arg#*\>*}"
      Arg=""${Arg%\<*}""
      \rm *+
    fi
    printf '%b\n' ${Color}"\t$Arg"${Nc}
    ##  Clean up after yourself.
    unset Arg Watch FB GG YH YT BL Color
    }
    falias()
    {
    clear
    if
      [ -z "$1" ]
    then
      printf '%b\n' ${Red}"\tPlease give me something to work with here. \x3a\x2d\x29"${Nc}
    else
      printf '%b\n' ${Cyan}"\tGrep found the following item(s) in history:"${Nc}
      history|awk '{for(i=2;i<=NF;i++){printf "%s ", $i}; printf "\n"}' |grep -i "$1"
      printf '%b\n' ${Cyan}"\tGrep found the following item(s) in ~/.bashrc:"${Nc}
      grep -i "$1" ${HOME}/.bashrc 2>&-|awk -F':' '{{printf "%s ",$2}; printf "\n"}'
      printf '%b\n' ${Cyan}"\tGrep found the following items in ~/.{aliase,function}s.sh:"${Nc}
      grep -i "$1" ${HOME}/.{aliase,function}s.sh 2>&-|awk -F':' '{{printf "%s ",$2}; printf "\n"}'
    fi
    }
  fi
fi

« As for a last »: What’s the difference between test, [ and [[ ?’

Tiny Matroska pinguins
Tiny Matroska pinguins (Photo credit: Act, don’t think)

Kindest regards,

Alex

ღ Ƹ̵̡ Ӝ̵̨̄ Ʒ ☆ ˜ ” * ° • . ¸ł¸ . • ° * ” ☆ ★ ☆ ę ˜

♫ d(。◕‿◕。)b ♪♪

Use the contact-form below, for feedback purposes.

Go back

Your message has been sent


Warning

Warning

Warning

Warning

Warning

Warning.

Back to top.

Leave a Reply (in md, or text)