Skip to content

Commit 2575d64

Browse files
authored
Merge pull request #2010 from gaelicWizard/plugin-projects
Plugin/projects: cleanup
2 parents 44a1b55 + a78d72e commit 2575d64

File tree

3 files changed

+58
-72
lines changed

3 files changed

+58
-72
lines changed

clean_files.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ plugins/available/osx-timemachine.plugin.bash
118118
plugins/available/osx.plugin.bash
119119
plugins/available/percol.plugin.bash
120120
plugins/available/plenv.plugin.bash
121+
plugins/available/projects.plugin.bash
121122
plugins/available/proxy.plugin.bash
122123
plugins/available/pyenv.plugin.bash
123124
plugins/available/python.plugin.bash
Lines changed: 54 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,57 @@
1-
cite about-plugin
2-
about-plugin 'quickly navigate configured paths with `pj` and `pjo`. example: "export PROJECT_PATHS=~/projects:~/work/projects"'
3-
4-
function pj {
5-
about 'navigate quickly to your various project directories'
6-
group 'projects'
7-
8-
9-
if [ -z "$PROJECT_PATHS" ]; then
10-
echo "error: PROJECT_PATHS not set"
11-
return 1
12-
fi
13-
14-
15-
local cmd
16-
local dest
17-
local -a dests
18-
19-
20-
if [ "$1" == "open" ]; then
21-
shift
22-
cmd="$EDITOR"
23-
fi
24-
cmd="${cmd:-cd}"
25-
26-
27-
if [ -z "$1" ]; then
28-
echo "error: no project provided"
29-
return 1
30-
fi
31-
32-
33-
# collect possible destinations to account for directories
34-
# with the same name in project directories
35-
for i in ${PROJECT_PATHS//:/$'\n'}; do
36-
if [ -d "$i"/"$1" ]; then
37-
dests+=("$i/$1")
38-
fi
39-
done
40-
41-
42-
# when multiple destinations are found, present a menu
43-
if [ ${#dests[@]} -eq 0 ]; then
44-
echo "error: no such project '$1'"
45-
return 1
46-
47-
elif [ ${#dests[@]} -eq 1 ]; then
48-
dest="${dests[0]}"
49-
50-
elif [ ${#dests[@]} -gt 1 ]; then
51-
PS3="Multiple project directories found. Please select one: "
52-
dests+=("cancel")
53-
select d in "${dests[@]}"; do
54-
case $d in
55-
"cancel")
56-
return
57-
;;
58-
*)
59-
dest=$d
60-
break
61-
;;
62-
esac
63-
done
64-
65-
else
66-
echo "error: please report this error"
67-
return 1 # should never reach this
68-
69-
fi
70-
71-
72-
$cmd "$dest"
1+
# shellcheck shell=bash
2+
about-plugin 'quickly navigate configured project paths'
3+
4+
: "${BASH_IT_PROJECT_PATHS:=$HOME/Projects:$HOME/src:$HOME/work}"
5+
6+
function pj() {
7+
about 'navigate quickly to your various project directories'
8+
group 'projects'
9+
10+
local proj="${1?${FUNCNAME[0]}: project name required}"
11+
local cmd PS3 dest d
12+
local -a dests
13+
14+
if [[ "$proj" == "open" ]]; then
15+
shift
16+
proj="${1}"
17+
cmd="${EDITOR?}"
18+
fi
19+
20+
# collect possible destinations to account for directories
21+
# with the same name in project directories
22+
IFS=':' read -ra dests <<< "${BASH_IT_PROJECT_PATHS?${FUNCNAME[0]}: project working folders must be configured}"
23+
for d in "${!dests[@]}"; do
24+
if [[ ! -d "${dests[d]}" ]]; then
25+
unset 'dests[d]'
26+
fi
27+
done
28+
29+
case ${#dests[@]} in
30+
0)
31+
_log_error "BASH_IT_PROJECT_PATHS must contain at least one existing location"
32+
return 1
33+
;;
34+
1)
35+
dest="${dests[*]}/${proj}"
36+
;;
37+
*)
38+
PS3="Multiple project directories found. Please select one: "
39+
dests+=("cancel")
40+
select d in "${dests[@]}"; do
41+
case $d in
42+
"cancel")
43+
return
44+
;;
45+
*)
46+
dest="${d}/${proj}"
47+
break
48+
;;
49+
esac
50+
done
51+
;;
52+
esac
53+
54+
"${cmd:-cd}" "${dest}"
7355
}
7456

7557
alias pjo="pj open"

template/bash_profile.template.bash

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ export IRC_CLIENT='irssi'
3838
# Set this to the command you use for todo.txt-cli
3939
export TODO="t"
4040

41+
# Set this to the location of your work or project folders
42+
#BASH_IT_PROJECT_PATHS="${HOME}/Projects:/Volumes/work/src"
43+
4144
# Set this to false to turn off version control status checking within the prompt for all themes
4245
export SCM_CHECK=true
4346
# Set to actual location of gitstatus directory if installed

0 commit comments

Comments
 (0)