-
Notifications
You must be signed in to change notification settings - Fork 0
/
prompt.fish
124 lines (101 loc) · 3.26 KB
/
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/usr/bin/env fish
# -*- coding: utf-8 -*-
# prompt
function fish_prompt
echo "\e[0;31mλ>\e[0m "
end
# NOTE: used to track prev command for pre-exec
set -g _PREV_CMD ""
# pre-exec handler
# if command is empty, print the current directory
function fish_preexec --on-event fish_preexec
# NOTE: use regex to extract command ONLY
# from last entry in history
set -g _PREV_CMD (string match -r '^[A-Za-z]*' $argv)
#? debug
# echo "set _PREV_CMD '$_PREV_CMD'"
end
function fish_preprompt --on-event fish_prompt
if test $_PREV_CMD = "" -o $_PREV_CMD = "where" -o $_PREV_CMD = "cd" -o $_PREV_CMD = "clear"
# echo (pwd)
echo "\e[0;31m$(pwd)\e[0m"
end
#? reset prev CMD
set -g _PREV_CMD ""
end
####
# set --path -a NESTED_FISH_LABELS
# function fish_prompt
# set -l command_status $status
# set -l question_mark_in_circle '?'\u20dd
# set -l color_orange (set_color DE935F brred) # base16 color 09
# set -l color_brown (set_color A3685A) # base16 color 0F
# # print hostname if client is remote
# set_color red
# if set -q SSH_TTY
# echo -n '@'(hostname)' '
# else
# echo -n '# '
# end
# # print nesting
# if test (count $NESTED_FISH_LABELS) -gt 0
# echo -ns '[' (set_color yellow) \
# (string join (set_color red)/(set_color yellow) $NESTED_FISH_LABELS) \
# (set_color red) '] '
# end
# # print current location
# if [ "$PWD" = "$HOME" ]
# set_color green; echo -n '~'
# else
# set -l parent_dir (dirname "$PWD")
# set_color blue
# if [ "$parent_dir" = "$HOME" ]
# echo -n '~'
# else
# echo -n (basename "$parent_dir")
# end
# echo -n ' → '
# set_color green; echo -n (basename "$PWD")
# end
# echo -n ' '
# # show some pretty git information if we're in a git repo
# set -l is_git_worktree (git rev-parse --is-inside-work-tree 2>/dev/null)
# if test "$is_git_worktree" = true
# if git rev-parse '@{u}' >/dev/null 2>&1
# # if an upstream is set, check how far ahead/behind the branch is
# set -l git_commits_ahead (git rev-list '@{u}..HEAD' | wc -l | awk '{print $1}')
# set -l git_commits_behind (git rev-list 'HEAD..@{u}' | wc -l | awk '{print $1}')
# if [ \( "$git_commits_ahead" -eq 0 \) -a \( "$git_commits_behind" -eq 0 \) ]
# set_color blue; echo -n '⦿'
# else
# if [ "$git_commits_behind" -gt 0 ]
# set_color red; echo -n "↓$git_commits_behind"
# end
# if [ "$git_commits_ahead" -gt 0 ]
# echo -n "$color_orange↑$git_commits_ahead"
# end
# end
# else
# # otherwise, indicate that an upstream is unknown
# echo -n "$color_orange$question_mark_in_circle"
# end
# set -l git_branch (git branch 2>/dev/null | sed -n '/\* /s///p')
# if test -n "$git_branch"
# set_color blue; echo -n ' ['
# # color the branch name differently if the working tree is dirty
# if [ (count (git status --porcelain)) -gt 0 ]
# echo -n "$color_orange"
# else
# set_color yellow
# end
# echo -n "$git_branch"
# set_color blue; echo -n '] '
# end
# end
# if [ "$command_status" -eq 0 ]
# echo -n $color_brown'λ: '
# else
# set_color red; echo -n 'λ! '
# end
# set_color normal
# end