From: Oleg Broytman Date: Sun, 7 Jun 2020 21:38:39 +0000 (+0300) Subject: bash: Use custom `short_curdir` instead of `\W` in `PS1` X-Git-Url: https://git.phdru.name/?a=commitdiff_plain;h=7ae7c0c571d5d950e4f6a349130a8f3401e09ea1;p=dotfiles.git bash: Use custom `short_curdir` instead of `\W` in `PS1` --- diff --git a/.profile b/.profile index c287c85..2cfb943 100644 --- a/.profile +++ b/.profile @@ -192,7 +192,12 @@ if [ -t 0 ] ; then ;; esac - OPS1=${OPS1}"${debian_chroot:+($debian_chroot)}\u@\h \W \\$" + if [ -r "$HOME"/admin/prog/short_curdir ]; then + . "$HOME"/admin/prog/short_curdir + OPS1=${OPS1}"${debian_chroot:+($debian_chroot)}\u@\h \`short_curdir\` \\$" + else + OPS1=${OPS1}"${debian_chroot:+($debian_chroot)}\u@\h \W \\$" + fi . "$ENV" else diff --git a/.shellrc b/.shellrc index a688876..541417a 100644 --- a/.shellrc +++ b/.shellrc @@ -152,6 +152,11 @@ if test -n "$BASH_VERSION"; then fi complete -W "`echo $BROWSER | sed 's/:/ /g'`" start-browser + if [ "`type -t short_curdir`" != function -a \ + -r "$HOME"/admin/prog/short_curdir ]; then + . "$HOME"/admin/prog/short_curdir + fi + #if type -p pip >/dev/null 2>&1; then # eval "`pip completion --bash`" # rm -rf /tmp/pip_build_"$USER" @@ -336,7 +341,11 @@ include() { mc() { if test -n "$BASH_VERSION"; then MC_SAVE_OPS1="$OPS1" - OPS1="\u@\h \W \\$" + if [ "`type -t short_curdir`" = function ]; then + OPS1="\u@\h \`short_curdir\` \\$" + else + OPS1="\u@\h \W \\$" + fi fi if [ -n "$SLOWTERM" ]; then diff --git a/admin/prog/short_curdir b/admin/prog/short_curdir new file mode 100644 index 0000000..62ede06 --- /dev/null +++ b/admin/prog/short_curdir @@ -0,0 +1,16 @@ +short_curdir() { + if [ "$PWD" = / ]; then + echo / + return + fi + if [ "$PWD" = "$HOME" ]; then + echo "~" + return + fi + local _short_curdir + _short_curdir="${PWD##*/}" # cut all directories, get base name + if [ "${#_short_curdir}" -gt 15 ]; then + _short_curdir="${_short_curdir::15}..." # cut long string + fi + echo "${_short_curdir}" +}