commit 16c9bffcee551194180836cb7ea68e6dee0636dc parent 9ec84e260727b5f4f00e4992d6bf9755917c4c97 Author: Anders Damsgaard <anders@adamsgaard.dk> Date: Thu, 12 Sep 2019 09:10:59 +0200 Add yashrc Diffstat:
A | .yashrc | | | 195 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 file changed, 195 insertions(+), 0 deletions(-)
diff --git a/.yashrc b/.yashrc @@ -0,0 +1,195 @@ +#!/bin/yash + +[ -f ~/.profile ] && . ~/.profile + +HISTFILE=~/.yash_history +HISTSIZE=65536 + +set --vi +set --brace-expand +set --extended-glob +set --no-clobber +set --no-unset +set --hist-space + +set --notify-le +set --le-no-conv-meta +set --le-predict + +bindkey --vi-insert '\^D' eof-or-delete +bindkey --vi-insert '\#' eof-or-delete +bindkey --vi-insert '\^F' forward-char +bindkey --vi-insert '\^K' forward-kill-line +bindkey --vi-insert '\^N' beginning-search-forward +bindkey --vi-insert '\^O' clear-candidates +bindkey --vi-insert '\^P' beginning-search-backward +bindkey --vi-insert '\^U' backward-kill-line +bindkey --vi-insert '\$' backward-kill-line +bindkey --vi-insert '\^W' backward-delete-viword +bindkey --vi-insert '\^Y' put-left +bindkey --vi-insert '\N' complete-next-column +bindkey --vi-insert '\P' complete-prev-column +bindkey --vi-insert '\^_' accept-prediction +bindkey --vi-command '\^N' beginning-search-forward +bindkey --vi-command '\^P' beginning-search-backward + +#bindkey '\^Z' _foreground +#_editor() { +# expect-verbatim echo hi +# accept-line +#} +#bindkey --vi-insert '\^E' _editor + +alias la='ls -a' ll='ls -l' lla='ll -a' +alias r='fc -s' + +# ensure job control works as expected +case $- in (*m*) + trap - TSTP TTIN TTOU +esac + +: ${LOGNAME:=$(logname)} ${HOSTNAME:=$(uname -n)} + +MAILCHECK=0 + +# emulate bash's $SHLVL +if [ "${_old_shlvl+set}" != set ]; then + _old_shlvl=${SHLVL-} +fi +SHLVL=$((_old_shlvl+1)) 2>/dev/null || SHLVL=1 +export SHLVL + +# initialize event handlers +COMMAND_NOT_FOUND_HANDLER=() +PROMPT_COMMAND=() +YASH_AFTER_CD=() + +# define prompt +if [ -n "${SSH_CONNECTION-}" ]; then + _hc='\fy.' # yellow hostname for SSH remote +else + #_hc='\fg.' # green hostname for local + _hc='\fD.' +fi +if [ "$(id -u)" -eq 0 ]; then + _uc='\fr.' # red username for root + _2c='\fr.' # red PS2 for root +else + _uc=$_hc _hc= # same username color as hostname for non-root user + _2c= # PS2 in normal color for non-root user +fi +# The main prompt ($YASH_PS1) contains the username, hostname, working +# directory, last exit status (only if non-zero), and $SHLVL (only if +# non-one). +YASH_PS1=$_uc'${LOGNAME}'$_hc'@${HOSTNAME%%.*}\fd. '\ +'${${${PWD:/~/\~}##*/}:-$PWD} ${{?:/0/}:+\\fr.$?\\fd. }${{SHLVL-0}:/1}\$ ' +YASH_PS1R='\fc.${_vcs_info}' +YASH_PS1S='\fo.' +YASH_PS2=$_2c'> ' +#YASH_PS2R= +YASH_PS2S=$YASH_PS1S +YASH_PS4='\fm.+ ' +YASH_PS4S='\fmo.' +unset _hc _uc _2c +# No escape sequences allowed in the POSIXly-correct mode. +PS1='${LOGNAME}@${HOSTNAME%%.*} '$PS1 + +# find escape sequence to change terminal window title +case "$TERM" in + (xterm|xterm[+-]*|gnome|gnome[+-]*|putty|putty[+-]*|cygwin) + _tsl='\033];' _fsl='\a' ;; + (*) + _tsl=$( (tput tsl 0; echo) 2>/dev/null | + sed -e 's;\\;\\\\;g' -e 's;;\\033;g' -e 's;;\\a;g' -e 's;%;%%;g') + _fsl=$( (tput fsl ; echo) 2>/dev/null | + sed -e 's;\\;\\\\;g' -e 's;;\\033;g' -e 's;;\\a;g' -e 's;%;%%;g') ;; +esac +# if terminal window title can be changed... +if [ "$_tsl" ] && [ "$_fsl" ]; then + + # set terminal window title on each prompt + _set_term_title() + if [ -t 2 ]; then + printf "$_tsl"'%s@%s:%s'"$_fsl" "${LOGNAME}" "${HOSTNAME%%.*}" \ + "${${PWD:/$HOME/\~}/#$HOME\//\~\/}" >&2 + fi + PROMPT_COMMAND=("$PROMPT_COMMAND" '_set_term_title') + + # reset window title when changing host or user + ssh() { + if [ -t 2 ]; then printf "$_tsl"'ssh %s'"$_fsl" "$*" >&2; fi + command ssh "$@" + } + su() { + if [ -t 2 ]; then printf "$_tsl"'su %s'"$_fsl" "$*" >&2; fi + command su "$@" + } + sudo() { + if [ -t 2 ]; then printf "$_tsl"'sudo %s'"$_fsl" "$*" >&2; fi + command sudo "$@" + } + +fi + +# define function that updates $_vcs_info and $_vcs_root +_update_vcs_info() { + typeset type branch + { + read --raw-mode type + read --raw-mode _vcs_root + read --raw-mode branch + } <( + exec 2>/dev/null + typeset COMMAND_NOT_FOUND_HANDLER= + while true; do + if [ -e .git ] || [ . -ef "${GIT_WORK_TREE-}" ]; then + printf 'git\n%s\n' "${GIT_WORK_TREE:-$PWD}" + git branch --no-color | sed -n '/^\*/s/^..//p' + exit + elif [ -d .hg ]; then + printf 'hg\n%s\n' "$PWD" + exec cat .hg/branch + elif [ -d .svn ]; then + printf 'svn\n' + _vcs_root=$(svn info --show-item=wc-root) + printf '%s\n' "$_vcs_root" + path=$(svn info --show-item=relative-url) + case $path in + (*/branches/*) + printf '%s\n' "${${path#*/branches/}%%/*}" + esac + exit + fi + if [ / -ef . ] || [ . -ef .. ]; then + exit + fi + cd -P .. + done + ) + case "$type#$branch" in + (hg#default) _vcs_info='hg';; + (git#master) _vcs_info='git';; + (*# ) _vcs_info="$type";; + (* ) _vcs_info="$type@$branch";; + esac +} +# update $_vcs_info on each prompt +PROMPT_COMMAND=("$PROMPT_COMMAND" '_update_vcs_info') + +# these aliases choose a version controlling program for the current directory +alias _vcs='${${_vcs_info:?not in a version-controlled directory}%%@*}' +alias ci='_vcs commit' +alias co='_vcs checkout' +alias di='_vcs diff' +alias log='_vcs log' +alias st='_vcs status' +alias up='_vcs update' + +# print file type when executing non-executable files +_file_type() +if [ -e "$1" ] && ! [ -d "$1" ]; then + file -- "$1" +fi +COMMAND_NOT_FOUND_HANDLER=("$COMMAND_NOT_FOUND_HANDLER" '_file_type "$@"') + +. ~/.commands.sh