Add switching to Git repositories via cdp.
parent
0c6167ae26
commit
714215113f
|
@ -73,6 +73,7 @@ section_end
|
||||||
##############################################################################
|
##############################################################################
|
||||||
# Profile tweaks and features
|
# Profile tweaks and features
|
||||||
|
|
||||||
|
PROFILE_CDP=${PROFILE_CDP:-1}
|
||||||
PROFILE_COMPOSER=${PROFILE_COMPOSER:-$(when_binary_available composer)}
|
PROFILE_COMPOSER=${PROFILE_COMPOSER:-$(when_binary_available composer)}
|
||||||
PROFILE_CUSTOM=${PROFILE_CUSTOM:-1}
|
PROFILE_CUSTOM=${PROFILE_CUSTOM:-1}
|
||||||
PROFILE_DEFAULT_TERM=${PROFILE_DEFAULT_TERM:-1}
|
PROFILE_DEFAULT_TERM=${PROFILE_DEFAULT_TERM:-1}
|
||||||
|
@ -92,6 +93,8 @@ PROFILE_SYSTEMD=${PROFILE_SYSTEMD:-$(when_binary_available systemctl)}
|
||||||
PROFILE_THEFUCK=${PROFILE_THEFUCK:-$(when_binary_available thefuck)}
|
PROFILE_THEFUCK=${PROFILE_THEFUCK:-$(when_binary_available thefuck)}
|
||||||
PROFILE_YARN=${PROFILE_YARN:-$(when_binary_available yarn)}
|
PROFILE_YARN=${PROFILE_YARN:-$(when_binary_available yarn)}
|
||||||
|
|
||||||
|
REPOSITORIES_PATH="${HOME}/Documents/Source"
|
||||||
|
|
||||||
section "profile variables"
|
section "profile variables"
|
||||||
log "$(set | grep '^PROFILE_')"
|
log "$(set | grep '^PROFILE_')"
|
||||||
section_end
|
section_end
|
||||||
|
@ -268,3 +271,40 @@ if [ $PROFILE_SYSTEMD -gt 0 ]; then
|
||||||
log "$(systemctl --user import-environment PATH)"
|
log "$(systemctl --user import-environment PATH)"
|
||||||
fi
|
fi
|
||||||
section_end
|
section_end
|
||||||
|
|
||||||
|
section "cdp"
|
||||||
|
if [ $PROFILE_CDP -gt 0 ]; then
|
||||||
|
find_git_project_paths() {
|
||||||
|
local cur
|
||||||
|
cur="$1"
|
||||||
|
while read -r found_path; do
|
||||||
|
echo "$(dirname "$found_path")"
|
||||||
|
done < <(find "$REPOSITORIES_PATH" -maxdepth 7 -mindepth 2 -type d -path "*/$cur/.git" 2>/dev/null)
|
||||||
|
}
|
||||||
|
|
||||||
|
cd_project() {
|
||||||
|
found_dir="$(find_git_project_paths "$1" | head -n1)"
|
||||||
|
if [ -z "$found_dir" ]; then
|
||||||
|
echo "Could not find project $1." >&2
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
cd "$found_dir"
|
||||||
|
}
|
||||||
|
|
||||||
|
_cd_project() {
|
||||||
|
local cur
|
||||||
|
COMPREPLY=()
|
||||||
|
cur="${COMP_WORDS[COMP_CWORD]}"
|
||||||
|
while read -r found_path; do
|
||||||
|
COMPREPLY+=("$(basename "$found_path")")
|
||||||
|
done < <(
|
||||||
|
# find git projects
|
||||||
|
find_git_project_paths "*$cur*"
|
||||||
|
)
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
complete -F _cd_project cd_project
|
||||||
|
|
||||||
|
alias cdp=cd_project
|
||||||
|
fi
|
||||||
|
section_end
|
||||||
|
|
Loading…
Reference in New Issue