-
Notifications
You must be signed in to change notification settings - Fork 9
/
fish_prompt.fish
101 lines (86 loc) · 2.2 KB
/
fish_prompt.fish
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
function _git_branch_name
echo (command git symbolic-ref HEAD 2> /dev/null | sed -e 's|^refs/heads/||')
end
function _is_git_dirty
echo (command git status -s --ignore-submodules=dirty 2> /dev/null)
end
## Function to show a segment
function _prompt_segment -d "Function to show a segment"
# Get colors
set -l bg $argv[1]
set -l fg $argv[2]
# Set 'em
set_color -b $bg
set_color $fg
# Print text
if [ -n "$argv[3]" ]
echo -n -s $argv[3]
end
# Reset
set_color -b normal
set_color normal
# Print padding
if [ (count $argv) = 4 ]
echo -n -s $argv[4]
end
end
function show_ssh_status -d "Function to show the ssh tag"
if test "$THEME_EDEN_HIDE_SSH_TAG" != 'yes'
if [ -n "$SSH_CLIENT" ]
if [ (id -u) = "0" ]
_prompt_segment red white "-SSH-" ' '
else
_prompt_segment blue white "-SSH-" ' '
end
end
end
end
function show_host -d "Show host & user name"
# Display [user & host] info
if test "$THEME_EDEN_SHOW_HOST" = 'yes'
if [ (id -u) = "0" ]
echo -n (set_color red)
else
echo -n (set_color blue)
end
echo -n ''(hostname|cut -d . -f 1)ˇ$USER' ' (set color normal)
end
end
function show_cwd -d "Function to show the current working directory"
if test "$theme_short_path" != 'yes' -a (prompt_pwd) != '~' -a (prompt_pwd) != '/'
set -l cwd (dirname (prompt_pwd))
test $cwd != '/'; and set cwd $cwd'/'
_prompt_segment normal cyan $cwd
end
set_color -o cyan
echo -n (basename (prompt_pwd))' '
set_color normal
end
function show_git_info -d "Show git branch and dirty state"
if [ (_git_branch_name) ]
set -l git_branch '['(_git_branch_name)']'
set_color -o
if [ (_is_git_dirty) ]
set_color -o red
echo -ne "$git_branch× "
else
set_color -o green
echo -ne "$git_branch "
end
set_color normal
end
end
function show_prompt_char -d "Terminate with a nice prompt char"
set -q THEME_EDEN_PROMPT_CHAR
or set -U THEME_EDEN_PROMPT_CHAR '»'
echo -n -s $normal $THEME_EDEN_PROMPT_CHAR ' '
end
function fish_prompt
# use tput to move cursor to line start
echo -ne (tput cr)
show_ssh_status
show_host
show_cwd
show_git_info
show_prompt_char
end