-
Notifications
You must be signed in to change notification settings - Fork 2
/
rustline.zsh
68 lines (54 loc) · 1.62 KB
/
rustline.zsh
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
DIR="$( dirname "$0" )"
if command -v "$DIR/target/release/rustline" &>/dev/null
then
RUSTLINE_COMMAND="$DIR/target/release/rustline"
elif command -v rustline &>/dev/null
then
RUSTLINE_COMMAND=$( command -v rustline )
else
echo ERROR: rustline command not found
fi
_rustline_append_precmd_function() {
if test -z "${precmd_functions[(re)$1]}" ; then
precmd_functions+=( $1 )
fi
}
integer _POWERLINE_JOBNUM
_rustline_set_jobnum() {
# If you are wondering why I am not using the same code as I use for bash
# ($(jobs|wc -l)): consider the following test:
# echo abc | less
# <C-z>
# . This way jobs will print
# [1] + done echo abc |
# suspended less -M
# ([ is in first column). You see: any line counting thingie will return
# wrong number of jobs. You need to filter the lines first. Or not use
# jobs built-in at all.
_RUSTLINE_JOBNUM=${(%):-%j}
}
color () {
echo "%{$bg[cyan]%}"
}
prompt_left() {
#echo $RUSTLINE_COMMAND left $@
#color
prompt=$($RUSTLINE_COMMAND left $@)
echo "$prompt"
}
_rustline_setup_prompt() {
emulate -L zsh
autoload -U colors && colors
_rustline_append_precmd_function _rustline_set_jobnum
#VIRTUAL_ENV_DISABLE_PROMPT=1
add_args=''
add_args+=' --last_exit_code=$?'
add_args+=' --last_pipe_status="$pipestatus"'
add_args+=' --shortened_path="${(%):-%~}"'
add_args+=' --jobnum=$_RUSTLINE_JOBNUM'
PROMPT='$(prompt_left '$add_args')'
RPROMPT='$("$RUSTLINE_COMMAND" right '$add_args')'
}
setopt promptsubst
setopt promptpercent
_rustline_setup_prompt