-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.bashrc
More file actions
67 lines (67 loc) · 2.41 KB
/
Copy path.bashrc
File metadata and controls
67 lines (67 loc) · 2.41 KB
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
# Toggle between normal PS1 and alternative (short) PS1
# Usage:
# toggle-prompt
# Toggle between normal and alternative PS1
# toggle-prompt help [aliases: h, -h, --help]
# Show help
# toggle-prompt PS1 <value> [alias: ps1]
# Change alternative PS1 to a new value
#
# Repository: https://github.com/davidstraka2/toggle-prompt
# Bugs: https://github.com/davidstraka2/toggle-prompt/issues
TOGGLE_PROMPT_PS1="-> "
__TOGGLE_PROMPT_PS1_FULL="$PS1"
__TOGGLE_PROMPT_STATE=1
function toggle-prompt () {
# If help is requested, show help
if [[ "$1" == "h" || "$1" == "help" || "$1" == "-h" || "$1" == "--help" ]]
then
echo -e "Toggle between normal PS1 and alternative (short) PS1"\
"\nUsage:"\
"\n $FUNCNAME"\
"\n Toggle between normal and alternative PS1"\
"\n $FUNCNAME help [aliases: h, -h, --help]"\
"\n Show help"\
"\n $FUNCNAME PS1 <value> [alias: ps1]"\
"\n Change alternative PS1 to a new value"
# Else if change of the alternative PS1 is requested
elif [[ "$1" == "PS1" || "$1" == "ps1" ]]
then
# Change the alternative PS1
TOGGLE_PROMPT_PS1="$2"
# If the current state is toggled to show alternative PS1, update PS1
if [ $__TOGGLE_PROMPT_STATE -eq 2 ]
then
PS1="$TOGGLE_PROMPT_PS1"
fi
# Inform user that the alternative PS1 has been set
echo "Set TOGGLE_PROMPT_PS1 to \"$TOGGLE_PROMPT_PS1\"."
# Else if any other argument is given, error
elif [ ! -z "$1" ]
then
echo "Unknown command given." >&2
return 1
# Else if toggle from full PS1 to alternative PS1 is requested
elif [ $__TOGGLE_PROMPT_STATE -eq 1 ]
then
# Update full PS1
__TOGGLE_PROMPT_PS1_FULL="$PS1"
# Update PS1 to alternative PS1
PS1="$TOGGLE_PROMPT_PS1"
# Update state
__TOGGLE_PROMPT_STATE=2
# Else if toggle from alternative PS1 to full PS1 is requested
elif [ $__TOGGLE_PROMPT_STATE -eq 2 ]
then
# Update alternative PS1
TOGGLE_PROMPT_PS1="$PS1"
# Update PS1 to full PS1
PS1="$__TOGGLE_PROMPT_PS1_FULL"
# Update state
__TOGGLE_PROMPT_STATE=1
# Else inform user of an unknown error to stderr
else
echo "Unknown error." >&2
return 1
fi
}