dotfiles

configuration files for shell, text editor, graphical environment, etc.
git clone git://src.adamsgaard.dk/dotfiles
Log | Files | Refs | README | LICENSE Back to index

commit bed93aaf5662b4e2aee60475d06685fb75004300
parent 260ed12be347551f9b1024de87a013a853b1f841
Author: Anders Damsgaard <anders@adamsgaard.dk>
Date:   Fri, 13 Sep 2019 09:49:00 +0200

Simplify prompt

Diffstat:
M.yashrc | 164+++++++++++++++++++++++++++++++++++++++++++------------------------------------
1 file changed, 89 insertions(+), 75 deletions(-)

diff --git a/.yashrc b/.yashrc @@ -1,5 +1,7 @@ #!/bin/yash +[ -r ~/.config/sh/profile ] && . ~/.config/sh/profile + HISTFILE=~/.yash_history HISTSIZE=65536 @@ -45,82 +47,94 @@ COMMAND_NOT_FOUND_HANDLER=() PROMPT_COMMAND=() YASH_AFTER_CD=() -# define prompt +## define prompt : ${LOGNAME:=$(logname)} ${HOSTNAME:=$(uname -n)} -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 - +#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 +# +# +## 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') -# 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') +PS1=\ +'${{{PWD:/~/\~}##*/}:-$PWD}'\ +"${SSH_CONNECTION:+@${HOSTNAME}}"\ +'${{?:/0/}:+?\\fr.$?\\fd.}'\ +"\fg\$\fd " +PS1R= +PS1S= +PS2='> ' +PS2R= +PS2S=$PS1S +PS4='\fm.+ ' +PS4S='\fmo.' -. $HOME/.config/sh/profile . $HOME/.config/sh/commands