ksh support, some cosmetics as well
This commit is contained in:
parent
7d4618cbd1
commit
5e1f6ac564
1 changed files with 77 additions and 19 deletions
92
shellrc
92
shellrc
|
@ -2,11 +2,13 @@
|
||||||
# If not running interactively, don't do anything
|
# If not running interactively, don't do anything
|
||||||
[[ $- != *i* ]] && return
|
[[ $- != *i* ]] && return
|
||||||
|
|
||||||
# common
|
|
||||||
# {{{ environment
|
# {{{ environment
|
||||||
# a bunch of functions and vars to make this whole thing work
|
# a bunch of functions and vars to make this whole thing work
|
||||||
is_zsh() [[ -n ${ZSH_VERSION} ]]
|
is_zsh() [[ -n ${ZSH_VERSION} ]]
|
||||||
if is_zsh; then
|
is_ksh() [[ -n ${KSH_VERSION} ]]
|
||||||
|
is_bash() [[ -n ${BASH_VERSION} ]]
|
||||||
|
|
||||||
|
if is_zsh || is_ksh; then
|
||||||
is_exec() [[ -x $(whence ${1}) ]]
|
is_exec() [[ -x $(whence ${1}) ]]
|
||||||
export HOSTNAME=${HOST}
|
export HOSTNAME=${HOST}
|
||||||
else
|
else
|
||||||
|
@ -117,9 +119,11 @@ screenoff-enable() { xset +dpms; xset s on; }
|
||||||
|
|
||||||
dotfiles-update() { git --work-tree="${dotfiles}" --git-dir="${dotfiles}/.git" pull; }
|
dotfiles-update() { git --work-tree="${dotfiles}" --git-dir="${dotfiles}/.git" pull; }
|
||||||
|
|
||||||
|
if ! is_ksh; then
|
||||||
hide-info() { hide_info=true; }
|
hide-info() { hide_info=true; }
|
||||||
|
|
||||||
unhide-info() { unset hide_info; }
|
unhide-info() { unset hide_info; }
|
||||||
|
fi
|
||||||
|
|
||||||
gruvbox-colors() {
|
gruvbox-colors() {
|
||||||
printf "\033]4;24;rgb:07/66/78\033\\"
|
printf "\033]4;24;rgb:07/66/78\033\\"
|
||||||
|
@ -207,9 +211,62 @@ if [[ -z "${DISPLAY}" ]]; then
|
||||||
x() { exec xinit -- :0 -nolisten tcp vt$XDG_VTNR; }
|
x() { exec xinit -- :0 -nolisten tcp vt$XDG_VTNR; }
|
||||||
fi
|
fi
|
||||||
# }}}
|
# }}}
|
||||||
if is_zsh; then
|
if is_ksh; then # {{{
|
||||||
# zsh
|
# {{{ ~ options
|
||||||
# {{{ options
|
set -o emacs
|
||||||
|
HISTSIZE=1000
|
||||||
|
HISTFILE=${HOME}/.ksh_history
|
||||||
|
# }}}
|
||||||
|
# {{{ ~ prompt
|
||||||
|
set -A colors 'black' 'red' 'green' 'yellow' 'blue' 'magenta' 'cyan' 'white'
|
||||||
|
for i in 0 1 2 3 4 5 6 7; do
|
||||||
|
eval "n${colors[$i]}='\[\e[0;3${i}m\]'"
|
||||||
|
eval "b${colors[$i]}='\[\e[1;3${i}m\]'"
|
||||||
|
done
|
||||||
|
reset='\[\e[0m\]'
|
||||||
|
bold='\[\e[1m\]'
|
||||||
|
lb="[ "
|
||||||
|
rb=" ]"
|
||||||
|
bb=":"
|
||||||
|
prompt_host="${fqdn}"
|
||||||
|
prompt_bang=">${reset}"
|
||||||
|
prompt_cwd="${bold}${PWD}${reset}"
|
||||||
|
UID=$(id -u)
|
||||||
|
if [[ ${UID} -eq 1000 || ${UID} -eq 1205 ]]; then
|
||||||
|
prompt_user=''
|
||||||
|
else
|
||||||
|
prompt_user="${nred}\u${reset} "
|
||||||
|
fi
|
||||||
|
prompt_info="${lb}${prompt_user}${prompt_host}${bb}${prompt_cwd} ksh:${nyellow}\v${reset}${rb}"
|
||||||
|
if [[ $UID -eq 0 ]]; then
|
||||||
|
prompt_bang_color="${nred}"
|
||||||
|
else
|
||||||
|
prompt_bang_color="${bold}"
|
||||||
|
fi
|
||||||
|
PS1="${prompt_info}${newline}${prompt_bang_color}${prompt_bang} "
|
||||||
|
# }}}
|
||||||
|
# {{{ ~ key bindings
|
||||||
|
# urxvt
|
||||||
|
bind '^[[7~'=beginning-of-line # home
|
||||||
|
bind '^[[8~'=end-of-line # end
|
||||||
|
# screen
|
||||||
|
bind '^[[1~'=beginning-of-line # home
|
||||||
|
bind '^[[4~'=end-of-line # end
|
||||||
|
# xterm
|
||||||
|
bind '^[[H~'=beginning-of-line # home
|
||||||
|
bind '^[[F~'=end-of-line # end
|
||||||
|
# all of them
|
||||||
|
bind '^[[5~'=backward-word # page up
|
||||||
|
bind '^[[6~'=forward-word # page down
|
||||||
|
# }}}
|
||||||
|
# {{{ ~ traps
|
||||||
|
# we want to see exit code on error (it also has to be the last entry here)
|
||||||
|
trap 'printf "\e[0m>> exit \e[1;37m%s\e[0m\n" $?' ERR
|
||||||
|
# }}}
|
||||||
|
return
|
||||||
|
fi # }}}
|
||||||
|
if is_zsh; then # {{{
|
||||||
|
# {{{ ~ options
|
||||||
setopt APPEND_HISTORY EXTENDED_HISTORY HIST_IGNORE_DUPS EXTENDED_GLOB AUTO_CD AUTO_PUSHD PRINT_EXIT_VALUE
|
setopt APPEND_HISTORY EXTENDED_HISTORY HIST_IGNORE_DUPS EXTENDED_GLOB AUTO_CD AUTO_PUSHD PRINT_EXIT_VALUE
|
||||||
unsetopt BEEP NO_MATCH NOTIFY
|
unsetopt BEEP NO_MATCH NOTIFY
|
||||||
|
|
||||||
|
@ -252,7 +309,7 @@ if is_zsh; then
|
||||||
zstyle ':vcs_info:*' formats " %s:%B%F{magenta}%r%f%%b %F{yellow}%b%f%u%c"
|
zstyle ':vcs_info:*' formats " %s:%B%F{magenta}%r%f%%b %F{yellow}%b%f%u%c"
|
||||||
fi
|
fi
|
||||||
# }}}
|
# }}}
|
||||||
# {{{ prompt
|
# {{{ ~ prompt
|
||||||
lb='[ '
|
lb='[ '
|
||||||
rb=' ]'
|
rb=' ]'
|
||||||
bb=':'
|
bb=':'
|
||||||
|
@ -274,7 +331,7 @@ if is_zsh; then
|
||||||
PROMPT3='%b%f?%B%F{green}#%f%b '
|
PROMPT3='%b%f?%B%F{green}#%f%b '
|
||||||
PROMPT4='%b%f+%N:%i%B%F{green}>%f%b '
|
PROMPT4='%b%f+%N:%i%B%F{green}>%f%b '
|
||||||
# }}}
|
# }}}
|
||||||
# {{{ key bindings
|
# {{{ ~ key bindings
|
||||||
bindkey -e
|
bindkey -e
|
||||||
# urxvt
|
# urxvt
|
||||||
bindkey '^[[7~' beginning-of-line # home
|
bindkey '^[[7~' beginning-of-line # home
|
||||||
|
@ -300,7 +357,7 @@ if is_zsh; then
|
||||||
bindkey '^[m' copy-prev-shell-word # alt + m
|
bindkey '^[m' copy-prev-shell-word # alt + m
|
||||||
bindkey -s '^j' '^atime ^m' # ctrl + j
|
bindkey -s '^j' '^atime ^m' # ctrl + j
|
||||||
# }}}
|
# }}}
|
||||||
# {{{ global aliases
|
# {{{ ~ global aliases
|
||||||
alias -g L='| less -R'
|
alias -g L='| less -R'
|
||||||
alias -g H='| head'
|
alias -g H='| head'
|
||||||
alias -g T='| tail'
|
alias -g T='| tail'
|
||||||
|
@ -322,7 +379,7 @@ if is_zsh; then
|
||||||
alias -g KU='| iconvku'
|
alias -g KU='| iconvku'
|
||||||
alias -g WU='| iconvwu'
|
alias -g WU='| iconvwu'
|
||||||
# }}}
|
# }}}
|
||||||
# {{{ suffix aliases
|
# {{{ ~ suffix aliases
|
||||||
editor=${EDITOR}
|
editor=${EDITOR}
|
||||||
text=( 'txt' 'xml' 'cfg' 'cnf' 'conf' 'ini' 'erb' 'pp' )
|
text=( 'txt' 'xml' 'cfg' 'cnf' 'conf' 'ini' 'erb' 'pp' )
|
||||||
for i in ${text[@]}; do
|
for i in ${text[@]}; do
|
||||||
|
@ -346,7 +403,7 @@ if is_zsh; then
|
||||||
alias -s exe=wine
|
alias -s exe=wine
|
||||||
fi
|
fi
|
||||||
# }}}
|
# }}}
|
||||||
# {{{ plugins
|
# {{{ ~ plugins
|
||||||
# command line syntax highlight from https://github.com/zsh-users/zsh-syntax-highlighting
|
# command line syntax highlight from https://github.com/zsh-users/zsh-syntax-highlighting
|
||||||
if [[ -r ${hl_script} ]]; then
|
if [[ -r ${hl_script} ]]; then
|
||||||
source ${hl_script}
|
source ${hl_script}
|
||||||
|
@ -355,9 +412,10 @@ if is_zsh; then
|
||||||
ZSH_HIGHLIGHT_STYLES[path_prefix]='fg=black,bold'
|
ZSH_HIGHLIGHT_STYLES[path_prefix]='fg=black,bold'
|
||||||
fi
|
fi
|
||||||
# }}}
|
# }}}
|
||||||
else
|
fi # }}}
|
||||||
|
if is_bash; then # {{{
|
||||||
# bash
|
# bash
|
||||||
# {{{ options
|
# {{{ ~ options
|
||||||
HISTSIZE=1000
|
HISTSIZE=1000
|
||||||
HISTCONTROL=ignoredups:ignorespace
|
HISTCONTROL=ignoredups:ignorespace
|
||||||
shopt -s histappend checkwinsize
|
shopt -s histappend checkwinsize
|
||||||
|
@ -365,7 +423,7 @@ else
|
||||||
|
|
||||||
extras=( "${HOME}/.bashrc.extras" )
|
extras=( "${HOME}/.bashrc.extras" )
|
||||||
# }}}
|
# }}}
|
||||||
# {{{ prompt
|
# {{{ ~ prompt
|
||||||
colors=('black' 'red' 'green' 'yellow' 'blue' 'magenta' 'cyan' 'white')
|
colors=('black' 'red' 'green' 'yellow' 'blue' 'magenta' 'cyan' 'white')
|
||||||
for i in 0 1 2 3 4 5 6 7; do
|
for i in 0 1 2 3 4 5 6 7; do
|
||||||
eval "n${colors[$i]}='\[\e[0;3${i}m\]'"
|
eval "n${colors[$i]}='\[\e[0;3${i}m\]'"
|
||||||
|
@ -399,7 +457,7 @@ else
|
||||||
}
|
}
|
||||||
PROMPT_COMMAND='precmd'
|
PROMPT_COMMAND='precmd'
|
||||||
# }}}
|
# }}}
|
||||||
# {{{ key bindings
|
# {{{ ~ key bindings
|
||||||
# time $command bind
|
# time $command bind
|
||||||
bind '"\C-j":"\C-atime \C-m"'
|
bind '"\C-j":"\C-atime \C-m"'
|
||||||
# urxvt
|
# urxvt
|
||||||
|
@ -415,18 +473,18 @@ else
|
||||||
bind '"\e[5~"':backward-word # page up
|
bind '"\e[5~"':backward-word # page up
|
||||||
bind '"\e[6~"':forward-word # page down
|
bind '"\e[6~"':forward-word # page down
|
||||||
# }}}
|
# }}}
|
||||||
# {{{ plugins
|
# {{{ ~ plugins
|
||||||
completion_path='/usr/share/bash-completion/bash_completion'
|
completion_path='/usr/share/bash-completion/bash_completion'
|
||||||
if [[ -n ${comp_enabled} && -r ${completion_path} ]]; then
|
if [[ -n ${comp_enabled} && -r ${completion_path} ]]; then
|
||||||
source ${completion_path}
|
source ${completion_path}
|
||||||
fi
|
fi
|
||||||
unset completion_path
|
unset completion_path
|
||||||
# }}}
|
# }}}
|
||||||
# {{{ traps
|
# {{{ ~ traps
|
||||||
# we want to see exit code on error (it also has to be the last entry here)
|
# we want to see exit code on error (it also has to be the last entry here)
|
||||||
trap 'printf "\e[0m>> exit \e[1;37m%s\e[0m\n" $?' ERR
|
trap 'printf "\e[0m>> exit \e[1;37m%s\e[0m\n" $?' ERR
|
||||||
# }}}
|
# }}}
|
||||||
fi
|
fi # }}}
|
||||||
# {{{ source extras
|
# {{{ source extras
|
||||||
for i in ${extras[@]}; do
|
for i in ${extras[@]}; do
|
||||||
if [[ -r ${i} ]]; then
|
if [[ -r ${i} ]]; then
|
||||||
|
|
Loading…
Reference in a new issue