2015-12-15 00:12:17 -05:00
|
|
|
#
|
2015-12-18 02:45:37 -05:00
|
|
|
# Utility Functions and Options
|
2015-12-15 00:12:17 -05:00
|
|
|
#
|
|
|
|
|
2015-12-15 18:49:15 -05:00
|
|
|
#
|
2016-10-28 17:17:34 -04:00
|
|
|
# Colours
|
2015-12-15 18:49:15 -05:00
|
|
|
#
|
|
|
|
|
2017-01-17 05:31:53 -05:00
|
|
|
if [[ ! -z ${terminfo[colors]} ]] && (( ${terminfo[colors]} >= 8 )); then
|
2016-10-28 17:17:34 -04:00
|
|
|
# ls Colors
|
|
|
|
if (( ${+commands[dircolors]} )); then
|
|
|
|
# GNU
|
|
|
|
if [[ -s ${HOME}/.dir_colors ]]; then
|
|
|
|
eval "$(dircolors --sh ${HOME}/.dir_colors)"
|
|
|
|
else
|
|
|
|
eval "$(dircolors --sh)"
|
|
|
|
fi
|
2016-09-30 10:36:40 -04:00
|
|
|
|
2016-10-28 17:17:34 -04:00
|
|
|
alias ls='ls --group-directories-first --color=auto'
|
2015-12-29 05:34:13 -05:00
|
|
|
|
2016-10-28 17:17:34 -04:00
|
|
|
else
|
|
|
|
# BSD
|
|
|
|
|
|
|
|
# colours for ls and completion
|
2017-05-14 05:05:42 -04:00
|
|
|
if (( ! ${+LSCOLORS} )); then
|
2017-05-10 04:27:13 -04:00
|
|
|
export LSCOLORS='exfxcxdxbxGxDxabagacad'
|
|
|
|
fi
|
2017-05-14 05:05:42 -04:00
|
|
|
if (( ! ${+LS_COLORS} )); then
|
2017-05-10 04:27:13 -04:00
|
|
|
export LS_COLORS='di=34:ln=35:so=32:pi=33:ex=31:bd=36;01:cd=33;01:su=31;40;07:sg=36;40;07:tw=32;40;07:ow=33;40;07:'
|
|
|
|
fi
|
2016-10-28 17:17:34 -04:00
|
|
|
|
|
|
|
# stock OpenBSD ls does not support colors at all, but colorls does.
|
|
|
|
if [[ $OSTYPE == openbsd* ]]; then
|
|
|
|
if (( ${+commands[colorls]} )); then
|
|
|
|
alias ls='colorls -G'
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
alias ls='ls -G'
|
|
|
|
fi
|
|
|
|
fi
|
2015-12-15 00:12:17 -05:00
|
|
|
|
2016-10-28 17:17:34 -04:00
|
|
|
# grep Colours
|
2017-05-14 05:05:42 -04:00
|
|
|
if (( ! ${+GREP_COLOR} )); then
|
2017-05-10 04:27:13 -04:00
|
|
|
export GREP_COLOR='37;45' #BSD
|
|
|
|
fi
|
2017-05-14 05:05:42 -04:00
|
|
|
if (( ! ${+GREP_COLORS} )); then
|
2017-05-10 04:27:13 -04:00
|
|
|
export GREP_COLORS="mt=${GREP_COLOR}" #GNU
|
|
|
|
fi
|
2016-10-28 17:17:34 -04:00
|
|
|
if [[ ${OSTYPE} == openbsd* ]]; then
|
2017-05-11 06:08:35 -04:00
|
|
|
if (( ${+commands[ggrep]} )); then
|
2016-10-28 17:17:34 -04:00
|
|
|
alias grep='ggrep --color=auto'
|
2016-04-25 01:49:05 -04:00
|
|
|
fi
|
|
|
|
else
|
2016-10-28 17:17:34 -04:00
|
|
|
alias grep='grep --color=auto'
|
2016-04-25 01:49:05 -04:00
|
|
|
fi
|
2015-12-18 02:45:37 -05:00
|
|
|
|
2016-10-28 17:17:34 -04:00
|
|
|
# less Colours
|
|
|
|
if [[ ${PAGER} == 'less' ]]; then
|
2017-05-14 05:05:42 -04:00
|
|
|
if (( ! ${+LESS_TERMCAP_mb} )); then
|
2017-05-10 04:27:13 -04:00
|
|
|
export LESS_TERMCAP_mb=$'\E[1;31m' # Begins blinking.
|
|
|
|
fi
|
2017-05-14 05:05:42 -04:00
|
|
|
if (( ! ${+LESS_TERMCAP_md} )); then
|
2017-05-10 04:27:13 -04:00
|
|
|
export LESS_TERMCAP_md=$'\E[1;31m' # Begins bold.
|
|
|
|
fi
|
2017-05-14 05:05:42 -04:00
|
|
|
if (( ! ${+LESS_TERMCAP_me} )); then
|
2017-05-10 04:27:13 -04:00
|
|
|
export LESS_TERMCAP_me=$'\E[0m' # Ends mode.
|
|
|
|
fi
|
2017-05-14 05:05:42 -04:00
|
|
|
if (( ! ${+LESS_TERMCAP_se} )); then
|
2017-05-10 04:27:13 -04:00
|
|
|
export LESS_TERMCAP_se=$'\E[0m' # Ends standout-mode.
|
|
|
|
fi
|
2017-05-14 05:05:42 -04:00
|
|
|
if (( ! ${+LESS_TERMCAP_so} )); then
|
2017-05-10 04:27:13 -04:00
|
|
|
export LESS_TERMCAP_so=$'\E[7m' # Begins standout-mode.
|
|
|
|
fi
|
2017-05-14 05:05:42 -04:00
|
|
|
if (( ! ${+LESS_TERMCAP_ue} )); then
|
2017-05-10 04:27:13 -04:00
|
|
|
export LESS_TERMCAP_ue=$'\E[0m' # Ends underline.
|
|
|
|
fi
|
2017-05-14 05:05:42 -04:00
|
|
|
if (( ! ${+LESS_TERMCAP_us} )); then
|
2017-05-10 04:27:13 -04:00
|
|
|
export LESS_TERMCAP_us=$'\E[1;32m' # Begins underline.
|
|
|
|
fi
|
2016-05-17 08:28:18 -04:00
|
|
|
fi
|
|
|
|
fi
|
2015-12-18 02:45:37 -05:00
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
# ls Aliases
|
|
|
|
#
|
|
|
|
|
|
|
|
alias l='ls -lAh' # all files, human-readable sizes
|
2016-10-28 17:17:34 -04:00
|
|
|
[[ -n ${PAGER} ]] && alias lm="l | ${PAGER}" # all files, human-readable sizes, use pager
|
2015-12-18 02:45:37 -05:00
|
|
|
alias ll='ls -lh' # human-readable sizes
|
|
|
|
alias lr='ll -R' # human-readable sizes, recursive
|
|
|
|
alias lx='ll -XB' # human-readable sizes, sort by extension (GNU only)
|
|
|
|
alias lk='ll -Sr' # human-readable sizes, largest last
|
|
|
|
alias lt='ll -tr' # human-readable sizes, most recent last
|
|
|
|
alias lc='lt -c' # human-readable sizes, most recent last, change time
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
# File Downloads
|
|
|
|
#
|
|
|
|
|
2015-12-19 17:05:43 -05:00
|
|
|
# order of preference: aria2c, axel, wget, curl. This order is derrived from speed based on personal tests.
|
2015-12-18 02:45:37 -05:00
|
|
|
if (( ${+commands[aria2c]} )); then
|
2015-12-18 07:23:00 -05:00
|
|
|
alias get='aria2c --max-connection-per-server=5 --continue'
|
2015-12-18 02:45:37 -05:00
|
|
|
elif (( ${+commands[axel]} )); then
|
|
|
|
alias get='axel --num-connections=5 --alternate'
|
|
|
|
elif (( ${+commands[wget]} )); then
|
|
|
|
alias get='wget --continue --progress=bar --timestamping'
|
|
|
|
elif (( ${+commands[curl]} )); then
|
|
|
|
alias get='curl --continue-at - --location --progress-bar --remote-name --remote-time'
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
# Resource Usage
|
|
|
|
#
|
|
|
|
|
|
|
|
alias df='df -kh'
|
|
|
|
alias du='du -kh'
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
# Always wear a condom
|
|
|
|
#
|
|
|
|
|
2016-01-23 15:04:43 -05:00
|
|
|
if [[ ${OSTYPE} == linux* ]]; then
|
|
|
|
alias chmod='chmod --preserve-root -v'
|
|
|
|
alias chown='chown --preserve-root -v'
|
|
|
|
fi
|
2015-12-18 02:45:37 -05:00
|
|
|
|
|
|
|
# not aliasing rm -i, but if safe-rm is available, use condom.
|
2016-01-23 19:45:55 -05:00
|
|
|
# if safe-rmdir is available, the OS is suse which has its own terrible 'safe-rm' which is not what we want
|
2016-10-28 17:17:34 -04:00
|
|
|
if (( ${+commands[safe-rm]} && ! ${+commands[safe-rmdir]} )); then
|
2016-01-23 19:45:55 -05:00
|
|
|
alias rm='safe-rm'
|
2015-12-18 02:45:37 -05:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
# Misc
|
|
|
|
#
|
|
|
|
|
|
|
|
mkcd() {
|
|
|
|
[[ -n ${1} ]] && mkdir -p ${1} && builtin cd ${1}
|
|
|
|
}
|