forked from netologist/theme-lambda
-
Notifications
You must be signed in to change notification settings - Fork 4
/
fish_right_prompt.fish
87 lines (76 loc) · 1.94 KB
/
fish_right_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
function fish_right_prompt
set -l exit_code $status
set -l cmd_duration $CMD_DURATION
__tmux_prompt
if test $exit_code -ne 0
set_color red
else
set_color green
end
printf '%d' $exit_code
if test $cmd_duration -ge 5000
set_color brcyan
else
set_color blue
end
printf ' (%s)' (__print_duration $cmd_duration)
# set_color 666666
# NOTE: ipatch, date taking too much space
# printf ' < %s' (date +%H:%M:%S)
set_color normal
end
function __tmux_prompt
set multiplexer (_is_multiplexed)
switch $multiplexer
case screen
set pane (_get_screen_window)
case tmux
set pane (_get_tmux_window)
end
set_color 666666
if test -z $pane
echo -n ""
else
echo -n $pane' | '
end
end
function _get_tmux_window
# tmux lsw | grep active | sed 's/\*.*$//g;s/: / /1' | awk '{ print $2 "-" $1 }' -
end
function _get_screen_window
set initial (screen -Q windows; screen -Q echo "")
set middle (echo $initial | sed 's/ /\n/g' | grep '\*' | sed 's/\*\$ / /g')
echo $middle | awk '{ print $2 "-" $1 }' -
end
function _is_multiplexed
set multiplexer ""
if test -z $TMUX
else
set multiplexer "tmux"
end
if test -z $WINDOW
else
set multiplexer "screen"
end
echo $multiplexer
end
function __print_duration
set -l duration $argv[1]
set -l millis (math $duration % 1000)
set -l seconds (math -s0 $duration / 1000 % 60)
set -l minutes (math -s0 $duration / 60000 % 60)
set -l hours (math -s0 $duration / 3600000 % 60)
if test $duration -lt 60000;
# Below a minute
printf "%d.%03ds\n" $seconds $millis
else if test $duration -lt 3600000;
# Below a hour
printf "%02d:%02d.%03d\n" $minutes $seconds $millis
else
# Everything else
printf "%02d:%02d:%02d.%03d\n" $hours $minutes $seconds $millis
end
end
function _convertsecs
printf "%02d:%02d:%02d\n" (math -s0 $argv[1] / 3600) (math -s0 (math $argv[1] \% 3600) / 60) (math -s0 $argv[1] \% 60)
end