profile (7341B)
1 # 2 # yash profile 3 # 4 # my "custom" funni configuration 5 # tbh it's just cherry picked configuration from the default config 6 # 7 8 set --brace-expand 9 set --extended-glob 10 set --no-unset 11 12 if command --identify --builtin-command history >/dev/null; then 13 14 # don't save commands starting with a space in history 15 set --hist-space 16 17 # prevent clearing history by accident 18 history() 19 if [ -t 0 ] && ( 20 for arg do 21 case "${arg}" in 22 (-[drsw]?* | --*=*) ;; 23 (-*c*) exit;; 24 esac 25 done 26 false 27 ) then 28 printf 'history: seems you are trying to clear the whole history.\n' >&2 29 printf 'are you sure? (yes/no) ' >&2 30 case "$(head -n 1)" in 31 ([Yy]*) command history "$@";; 32 (*) printf 'history: cancelled.\n' >&2;; 33 esac 34 else 35 command history "$@" 36 fi 37 38 fi 39 40 # if yash is built with line-editing enabled... 41 if command --identify --builtin-command bindkey >/dev/null; then 42 # print job status update ASAP, but only while line-editing 43 set --notify-le 44 45 # some terminfo data are broken; meta flags have to be ignored for UTF-8 46 set --le-no-conv-meta 47 48 # enable command line prediction 49 set --le-predict 50 51 set -o vi 52 fi 53 54 case $- in (*m*) 55 trap - TSTP TTIN TTOU 56 esac 57 58 # variables needed for command history 59 60 if ! [ "${HISTFILE-}" ]; then 61 HISTFILE=${XDG_STATE_HOME:-~/.local/state}/yash/history 62 63 # handle old default history path 64 if [ -f ~/.yash_history ]; then 65 printf 'Note: The default history file location has been changed to "%s".\n' "$HISTFILE" >&2 66 HISTFILE=~/.yash_history 67 printf 'Please consider moving the existing file from the current location "%s".\n' "$HISTFILE" >&2 68 fi 69 fi 70 71 # create HISTFILE parent directory if missing 72 ! [ -d "${HISTFILE%/*}" ] && mkdir -p "${HISTFILE%/*}" 73 74 HISTSIZE=5000 75 76 # HISTRMDUP makes prediction less accurate 77 # HISTRMDUP=500 78 79 # default mail check interval is too long 80 MAILCHECK=0 81 82 # emulate bash's $SHLVL 83 if [ "${_old_shlvl+set}" != set ]; then 84 _old_shlvl=${SHLVL-} 85 fi 86 SHLVL=$((_old_shlvl+1)) 2>/dev/null || SHLVL=1 87 export SHLVL 88 89 # initialize event handlers 90 COMMAND_NOT_FOUND_HANDLER=() 91 PROMPT_COMMAND=() 92 POST_PROMPT_COMMAND=() 93 YASH_AFTER_CD=() 94 95 if [[ "$(id -u)" -eq 0 ]]; then 96 export YASH_PS1='\[\fro.\]${USER} [\[\fD.\] ${PWD/#"$HOME"/\~} \[\fro.\]]$ \[\fD.\]' 97 else 98 export YASH_PS1='\[\fgo.\]${USER} [\[\fD.\] ${PWD/#"$HOME"/\~} \[\fgo.\]]$ \[\fD.\]' 99 fi 100 export YASH_PS1S="\fD." 101 102 # PS1='${LOGNAME}@${HOSTNAME%%.*} '$PS1 103 104 case "$TERM" in 105 (xterm|xterm[+-]*|gnome|gnome[+-]*|putty|putty[+-]*|cygwin) 106 _tsl='\033];' _fsl='\a' ;; 107 (*) 108 _tsl=$( (tput tsl 0; echo) 2>/dev/null | 109 sed -e 's;\\;\\\\;g' -e 's;;\\033;g' -e 's;;\\a;g' -e 's;%;%%;g') 110 _fsl=$( (tput fsl ; echo) 2>/dev/null | 111 sed -e 's;\\;\\\\;g' -e 's;;\\033;g' -e 's;;\\a;g' -e 's;%;%%;g') ;; 112 esac 113 # if terminal window title can be changed... 114 if [ "$_tsl" ] && [ "$_fsl" ]; then 115 # set terminal window title on each prompt 116 _set_term_title() 117 if [ -t 2 ]; then 118 printf "$_tsl"'%s@%s:%s'"$_fsl" "${LOGNAME}" "${HOSTNAME%%.*}" \ 119 "${${PWD:/$HOME/\~}/#$HOME\//\~\/}" >&2 120 fi 121 PROMPT_COMMAND=("$PROMPT_COMMAND" '_set_term_title') 122 123 # reset window title when changing host or user 124 ssh() { 125 if [ -t 2 ]; then printf "$_tsl"'ssh %s'"$_fsl" "$*" >&2; fi 126 command ssh "$@" 127 } 128 su() { 129 if [ -t 2 ]; then printf "$_tsl"'su %s'"$_fsl" "$*" >&2; fi 130 command su "$@" 131 } 132 sudo() { 133 if [ -t 2 ]; then printf "$_tsl"'sudo %s'"$_fsl" "$*" >&2; fi 134 command sudo "$@" 135 } 136 doas() { 137 if [ -t 2 ]; then printf "$_tsl"'doas %s'"$_fsl" "$*" >&2; fi 138 command doas "$@" 139 } 140 fi 141 142 # define function that updates $_vcs_info and $_vcs_root 143 _update_vcs_info() { 144 typeset type branch 145 { 146 read --raw-mode type 147 read --raw-mode _vcs_root 148 read --raw-mode branch 149 } <( 150 exec 2>/dev/null 151 typeset COMMAND_NOT_FOUND_HANDLER= 152 while true; do 153 if [ -e .git ] || [ . -ef "${GIT_WORK_TREE-}" ]; then 154 printf 'git\n%s\n' "${GIT_WORK_TREE:-$PWD}" 155 git branch --no-color | sed -n '/^\*/s/^..//p' 156 exit 157 elif [ -d .hg ]; then 158 printf 'hg\n%s\n' "$PWD" 159 exec cat .hg/branch 160 elif [ -d .svn ]; then 161 printf 'svn\n' 162 _vcs_root=$(svn info --show-item=wc-root) 163 printf '%s\n' "$_vcs_root" 164 path=$(svn info --show-item=relative-url) 165 case $path in 166 (*/branches/*) 167 printf '%s\n' "${${path#*/branches/}%%/*}" 168 esac 169 exit 170 fi 171 if [ / -ef . ] || [ . -ef .. ]; then 172 exit 173 fi 174 \command cd -P .. 175 done 176 ) 177 case "$type#$branch" in 178 (hg#default) _vcs_info='hg';; 179 (git#master) _vcs_info='git';; 180 (*# ) _vcs_info="$type";; 181 (* ) _vcs_info="$type@$branch";; 182 esac 183 184 YASH_PS1R="\fc.${_vcs_info}" 185 } 186 # update $_vcs_info on each prompt 187 PROMPT_COMMAND=("$PROMPT_COMMAND" '_update_vcs_info') 188 189 # these aliases choose a version controlling program for the current directory 190 alias _vcs='${${_vcs_info:?not in a version-controlled directory}%%@*}' 191 alias ci='_vcs commit' 192 alias co='_vcs checkout' 193 alias di='_vcs diff' 194 alias log='_vcs log' 195 alias st='_vcs status' 196 alias up='_vcs update' 197 198 # when a directory name is entered as a command, treat as "cd" 199 _autocd() 200 if [ -d "$1" ]; then 201 HANDLED=true 202 cd -- "$@" 203 break -i 204 fi 205 COMMAND_NOT_FOUND_HANDLER=("$COMMAND_NOT_FOUND_HANDLER" '_autocd "$@"') 206 207 # treat command names starting with % as "fg" 208 _autofg() 209 if [ $# -eq 1 ]; then 210 case $1 in (%*) 211 HANDLED=true 212 fg "$1" 213 break -i 214 esac 215 fi 216 COMMAND_NOT_FOUND_HANDLER=("$COMMAND_NOT_FOUND_HANDLER" '_autofg "$@"') 217 218 # print file type when executing non-executable files 219 _file_type() 220 if [ -e "$1" ] && ! [ -d "$1" ]; then 221 file -- "$1" 222 fi 223 COMMAND_NOT_FOUND_HANDLER=("$COMMAND_NOT_FOUND_HANDLER" '_file_type "$@"') 224 225 bindkey --vi-insert '\^L' clear-and-redraw-all 226 bindkey --vi-command '\^L' clear-and-redraw-all 227 228 # vim: set et sw=8 sts=8 tw=78 ft=sh: