1
0
Fork 0
mirror of synced 2024-06-02 23:31:11 -04:00

Add less termcap colour variables

Set `less` termcap colour variables, and update the module README.md.
Change the code to enclose all colour logic within a
`(( ${terminfo[colors]} >= 8 ))` condition.
Check if `PAGER` is set before setting the `lm` alias.

Keeping the British "colour" spelling. :-)

Closes #101
This commit is contained in:
Eric Nielsen 2016-10-28 16:17:34 -05:00 committed by Matt Hamilton
parent 1801faf39c
commit 7a289c4c0d
2 changed files with 47 additions and 37 deletions

View file

@ -3,7 +3,7 @@ Utility
Utility aliases and functions. Utility aliases and functions.
Adds colour to `ls` and `grep`. Adds colour to `ls`, `grep` and `less`.
Aliases Aliases
------- -------

View file

@ -3,9 +3,11 @@
# #
# #
# ls Colours # Colours
# #
if (( ${terminfo[colors]} >= 8 )); then
# ls Colors
if (( ${+commands[dircolors]} )); then if (( ${+commands[dircolors]} )); then
# GNU # GNU
if [[ -s ${HOME}/.dir_colors ]]; then if [[ -s ${HOME}/.dir_colors ]]; then
@ -19,7 +21,7 @@ if (( ${+commands[dircolors]} )); then
else else
# BSD # BSD
# colors for ls and completion # colours for ls and completion
export LSCOLORS='exfxcxdxbxGxDxabagacad' export LSCOLORS='exfxcxdxbxGxDxabagacad'
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:' 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:'
@ -33,11 +35,7 @@ else
fi fi
fi fi
#
# grep Colours # grep Colours
#
export GREP_COLOR='37;45' #BSD export GREP_COLOR='37;45' #BSD
export GREP_COLORS="mt=${GREP_COLOR}" #GNU export GREP_COLORS="mt=${GREP_COLOR}" #GNU
if [[ ${OSTYPE} == openbsd* ]]; then if [[ ${OSTYPE} == openbsd* ]]; then
@ -48,13 +46,25 @@ else
alias grep='grep --color=auto' alias grep='grep --color=auto'
fi fi
# less Colours
if [[ ${PAGER} == 'less' ]]; then
export LESS_TERMCAP_mb=$'\E[1;31m' # Begins blinking.
export LESS_TERMCAP_md=$'\E[1;31m' # Begins bold.
export LESS_TERMCAP_me=$'\E[0m' # Ends mode.
export LESS_TERMCAP_se=$'\E[0m' # Ends standout-mode.
export LESS_TERMCAP_so=$'\E[7m' # Begins standout-mode.
export LESS_TERMCAP_ue=$'\E[0m' # Ends underline.
export LESS_TERMCAP_us=$'\E[1;32m' # Begins underline.
fi
fi
# #
# ls Aliases # ls Aliases
# #
alias l='ls -lAh' # all files, human-readable sizes alias l='ls -lAh' # all files, human-readable sizes
alias lm="l | ${PAGER}" # all files, human-readable sizes, use pager [[ -n ${PAGER} ]] && alias lm="l | ${PAGER}" # all files, human-readable sizes, use pager
alias ll='ls -lh' # human-readable sizes alias ll='ls -lh' # human-readable sizes
alias lr='ll -R' # human-readable sizes, recursive alias lr='ll -R' # human-readable sizes, recursive
alias lx='ll -XB' # human-readable sizes, sort by extension (GNU only) alias lx='ll -XB' # human-readable sizes, sort by extension (GNU only)
@ -98,7 +108,7 @@ fi
# not aliasing rm -i, but if safe-rm is available, use condom. # not aliasing rm -i, but if safe-rm is available, use condom.
# if safe-rmdir is available, the OS is suse which has its own terrible 'safe-rm' which is not what we want # if safe-rmdir is available, the OS is suse which has its own terrible 'safe-rm' which is not what we want
if (( ${+commands[safe-rm]} )) && (( ! ${+commands[safe-rmdir]} )); then if (( ${+commands[safe-rm]} && ! ${+commands[safe-rmdir]} )); then
alias rm='safe-rm' alias rm='safe-rm'
fi fi