Last active
March 6, 2016 00:40
-
-
Save visnup/98330 to your computer and use it in GitHub Desktop.
bash prompt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function fish_prompt --description 'Write out the prompt' | |
set git_sha (git rev-parse --short HEAD 2>/dev/null) | |
set git_branch (git rev-parse --abbrev-ref HEAD 2>/dev/null) | |
set git " $git_sha $git_branch " | |
if [ $git = ' ' ] | |
set git '' | |
end | |
set length (echo [ 00:00 AM -$git(prompt_pwd) ] | wc -c | tr -d ' ') | |
set fill (printf '%*s\n' (math (tput cols)-$length) '' | tr ' ' –) | |
set_color $fish_color_autosuggestion | |
echo '' | |
echo [ (date +'%H:%M %p') –(set_color $fish_color_param)$git(set_color $fish_color_autosuggestion)$fill (set_color $fish_color_cwd)(prompt_pwd)(set_color $fish_color_autosuggestion) ] | |
switch $USER | |
case root toor | |
echo '# ' | |
case '*' | |
echo '$ ' | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# the goals of this prompt are: | |
# | |
# - give plenty of room for the command | |
# - don't start causing weird terminal cursor issues when inside a deeply nested | |
# directory | |
# - help visually distinguish one command from the next | |
# - visually indicate when on another machine | |
# | |
# thanks to qmrw for a heavy bash-based cleanup | |
# | |
# based heavily on termwide prompt by Giles - created 2 November 98 | |
# http://www.linuxselfhelp.com/howtos/Bash-Prompt/Bash-Prompt-HOWTO-12.html | |
# | |
# install by cloning this file and adding: | |
# . /path/to/script/termwide.sh | |
# to .profile or similar | |
function update_termwide { | |
PS_PWD="${PWD/#$HOME/~}" | |
PS_FILL="" | |
PS_GIT=" $(git rev-parse --short HEAD 2>/dev/null) " | |
PS_BRANCH=$(git rev-parse --abbrev-ref HEAD 2>/dev/null) | |
if [ "$PS_BRANCH" != "HEAD" ]; then PS_GIT="$PS_GIT$PS_BRANCH "; fi | |
if [ "$PS_GIT" == " " ]; then PS_GIT=''; fi | |
local len_prompt=$(echo -n "[ 00:00 AM -${PS_GIT}${PS_PWD} ]" | wc -c | tr -d " ") | |
local len_rfill=$((COLUMNS - len_prompt - 1)) | |
while [[ $len_rfill > 0 ]]; do | |
PS_FILL="${PS_FILL}─" | |
len_rfill=$((len_rfill - 1)) | |
done | |
if [[ $len_rfill < 0 ]]; then | |
local len_cut=$((3 - len_rfill)) | |
PS_PWD="...$(echo -n $PS_PWD | sed -e "s/\(^.\{$len_cut\}\)\(.*\)/\2/")" | |
fi | |
} | |
PROMPT_COMMAND="update_termwide${PROMPT_COMMAND:+; $PROMPT_COMMAND}" | |
function termwide { | |
local esc_white="\[\033[1;37m\]" | |
local esc_gray="\[\033[1;30m\]" | |
local esc_reset="\[\033[0m\]" | |
PS1="$esc_gray[ $esc_white\@$esc_gray ─$esc_white\${PS_GIT}$esc_gray\${PS_FILL} \${PS_PWD} ]\n\ | |
\$$esc_reset " | |
PS2=">$esc_reset " | |
} | |
termwide | |
# vim: ts=4 sw=4 et |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment