-
Notifications
You must be signed in to change notification settings - Fork 1
/
retag.plugin.zsh
executable file
·48 lines (42 loc) · 1.77 KB
/
retag.plugin.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
# Build the binary if it is not already present and not on the PATH
retag_dir=$(dirname $0)
if ! which retag >/dev/null; then
PATH="$PATH:$retag_dir/target/release"
if [[ ! -f "$retag_dir/target/release/retag" ]]; then
if which rustc >/dev/null && which cargo >/dev/null; then
echo "Building retag"
current_dir=$(pwd)
cd $retag_dir && cargo build --release && cd $current_dir
else
print "retag binary not present, and rustc and cargo are also not present\n"\
"Please install Rust or add the retag binary to your PATH" >&2
return
fi
fi
fi
function retag_cwd() {
# Check if this is a Git repo
PROJECT_ROOT=`git rev-parse --show-toplevel 2> /dev/null`
if (( $? != 0 )); then
PROJECT_ROOT=""
fi
# If we just moved out of our current project, stop retag
if [[ -n $CURRENT_RETAG_DIR && $PROJECT_ROOT != $CURRENT_RETAG_DIR ]]; then
start-stop-daemon --stop -p "$CURRENT_RETAG_DIR/.git/retag.pid" --exec $(which retag) --oknodo >/dev/null 2>/dev/null
fi
# If we moved into a new project, stqrt retag up
if [[ "$PROJECT_ROOT" != "" ]]; then
# TODO: Add daemonization to retag itself and drop start-stop-daemon
start-stop-daemon --start -m --pidfile "$PROJECT_ROOT/.git/retag.pid" --exec $(which retag) -b --chdir $PROJECT_ROOT >/dev/null 2>/dev/null
if (( $? == 0 )); then
export CURRENT_RETAG_DIR=$(pwd)
fi
elif [[ -n $CURRENT_RETAG_DIR ]]; then
unset CURRENT_RETAG_DIR
fi
}
# Append retag_cwd to the chpwd_functions array, so it will be called on cd
# http://zsh.sourceforge.net/Doc/Release/Functions.html
if ! (( $chpwd_functions[(I)retag_cwd] )); then
chpwd_functions+=(retag_cwd)
fi