From 87fa984e2595fd6aec18ce8e08996bba164b18c6 Mon Sep 17 00:00:00 2001 From: Daniel Flanagan Date: Thu, 3 Mar 2016 13:09:37 -0600 Subject: [PATCH] short cwd in bash prompt --- sh/bashrc | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/sh/bashrc b/sh/bashrc index 6083baa..3f905e9 100644 --- a/sh/bashrc +++ b/sh/bashrc @@ -59,6 +59,14 @@ COLOR_RESET='\[\e[0m\]' PROMPT_SUCCESS_COLOR='\[\e[0;34m\]' PROMPT_FAILURE_COLOR='\[\e[0;31m\]' DIR_COLOR='\[\e[0;33m\]' +sps() { + name="$PWD" + [[ "$name" =~ ^"$HOME"(/|$) ]] && name="~${name#$HOME}" + curdir=$(echo "$PWD" | sed -r 's|.*/(.+)$|\1|g') + name=$(echo "$name" | sed -r 's|/(..)[^/]*|/\1|g' | sed -r 's|(.*/)(.+)$|\1|g') + [[ "$name" == "~" ]] && curdir="" + echo "$name$curdir" +} prompt_command_func() { RET=$? @@ -67,7 +75,7 @@ prompt_command_func() else STATUS_COLOR=$PROMPT_FAILURE_COLOR fi; - PS1="$STATUS_COLOR\u@\h$COLOR_RESET $DIR_COLOR\w$COLOR_RESET " + PS1="$STATUS_COLOR\u@\h$COLOR_RESET $DIR_COLOR$(eval "sps")$COLOR_RESET " } export PROMPT_COMMAND="prompt_command_func"