Use fd/find to locate git repositories in project.sh
This commit is contained in:
26
project.sh
26
project.sh
@@ -2,19 +2,27 @@
|
||||
|
||||
set -e
|
||||
|
||||
projects=()
|
||||
projects_dir=$HOME/Projects
|
||||
|
||||
# Get list of projects from ~/Projects
|
||||
for dir in $HOME/Projects/**/*; do
|
||||
if [ -d $dir ]; then
|
||||
projects+=(${dir#$HOME/Projects/})
|
||||
fi
|
||||
done
|
||||
# Find git repositories and worktrees
|
||||
if command -v fd &>/dev/null; then
|
||||
projects=$(
|
||||
fd -H '^\.git$' "$projects_dir" |
|
||||
sed -E -e "s|^$projects_dir/||" -e 's|/\.git/?$||' |
|
||||
sort -u
|
||||
)
|
||||
else
|
||||
projects=$(
|
||||
find "$projects_dir" \( -name 'node_modules' -o -name '.git' \) -prune -name '.git' -print |
|
||||
sed -E -e "s|^$projects_dir/||" -e 's|/\.git/?$||' |
|
||||
sort -u
|
||||
)
|
||||
fi
|
||||
|
||||
project=$(
|
||||
echo "${projects[@]}" | tr ' ' '\n' | sort -u |
|
||||
echo "$projects" |
|
||||
fzf --layout=reverse --info=hidden --border=rounded --cycle
|
||||
)
|
||||
|
||||
tmux new-window -n $project -c ~/Projects/$project
|
||||
tmux new-window -n "$project" -c "$projects_dir/$project"
|
||||
~/.local/share/tmux/layouts/window-auto
|
||||
|
||||
Reference in New Issue
Block a user