forked from oh-my-fish/theme-cmorrell.com
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fish_prompt.fish
94 lines (82 loc) · 2.05 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
set -g pad " "
set -g default_user kfuntov
## 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
end
## Function to show current status
function show_status -d "Function to show the current status"
if [ $RETVAL -ne 0 ]
prompt_segment red white " ▲ "
set pad ""
end
if [ -n "$SSH_CLIENT" ]
prompt_segment blue white " SSH: "
set pad ""
end
end
function show_virtualenv -d "Show active python virtual environments"
if set -q VIRTUAL_ENV
set -l venvname (basename "$VIRTUAL_ENV")
prompt_segment normal white " ($venvname) "
end
end
## Show user if not in default users
function show_user -d "Show user"
if not contains $USER $default_user; or test -n "$SSH_CLIENT"
set -l host (hostname -s)
set -l who (whoami)
prompt_segment normal yellow " $who"
# Skip @ bit if hostname == username
if [ "$who" != "$host" ]
prompt_segment normal white "@"
prompt_segment normal green "$host "
set pad ""
end
end
end
function _set_venv_project --on-variable VIRTUAL_ENV
if test -e $VIRTUAL_ENV/.project
set -g VIRTUAL_ENV_PROJECT (cat $VIRTUAL_ENV/.project)
end
end
# Show directory
function show_pwd -d "Show the current directory"
set -l pwd
if [ (string match -r '^'"$VIRTUAL_ENV_PROJECT" $PWD) ]
set pwd (string replace -r '^'"$VIRTUAL_ENV_PROJECT"'($|/)' '≫ $1' $PWD)
else
set pwd (prompt_pwd)
end
prompt_segment normal blue "$pad$pwd "
end
# Show prompt w/ privilege cue
function show_prompt -d "Shows prompt with cue for current priv"
set -l uid (id -u $USER)
if [ $uid -eq 0 ]
prompt_segment red white " ! "
set_color normal
echo -n -s " "
else
prompt_segment normal white " \$ "
end
set_color normal
end
## SHOW PROMPT
function fish_prompt
set -g RETVAL $status
show_status
show_virtualenv
show_user
show_pwd
show_prompt
end