Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: GH-296: Add missing command completions #297

Merged
merged 1 commit into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions resources/shell/bash/ghr-completion.bash
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,17 @@ __ghr_complete() {
cword="${COMP_WORDS[COMP_CWORD]}"

if [ "${COMP_CWORD}" = 1 ]; then
COMPREPLY=($(__ghr_complete__static "${cword}" --help cd clone delete help init open browse path profile shell version))
COMPREPLY=($(__ghr_complete__static "${cword}" --help add browse cd clone delete help init list open path profile shell sync version))
return 0
fi

case "${COMP_WORDS[1]}" in
add)
COMPREPLY=($(__ghr_complete__static "${cword}" --help))
;;
browse)
COMPREPLY=($(__ghr_complete__repos "${cword}"))
;;
cd)
COMPREPLY=($(__ghr_complete__repos "${cword}"))
;;
Expand All @@ -60,6 +66,9 @@ __ghr_complete() {
init)
COMPREPLY=($(__ghr_complete__static "${cword}" --help))
;;
list)
COMPREPLY=($(__ghr_complete__static "${cword}" --help --no-host --no-owner -p --path))
;;
open)
if [ "${COMP_CWORD}" = 2 ]; then
COMPREPLY=($(__ghr_complete__repos "${cword}" --help))
Expand All @@ -68,9 +77,6 @@ __ghr_complete() {
COMPREPLY=($(compgen -c -- "${cword}"))
fi
;;
browse)
COMPREPLY=($(__ghr_complete__repos "${cword}"))
;;
path)
COMPREPLY=($(__ghr_complete__repos "${cword}"))
;;
Expand All @@ -90,6 +96,9 @@ __ghr_complete() {
shell)
COMPREPLY=($(__ghr_complete__static "${cword}" --help))
;;
sync)
COMPREPLY=($(__ghr_complete__static "${cword}" --help dump restore))
;;
version)
COMPREPLY=($(__ghr_complete__static "${cword}" --help))
;;
Expand Down
13 changes: 11 additions & 2 deletions resources/shell/fish/ghr-completion.fish
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,25 @@ end
complete -c ghr -f

# Complete commands with their description
complete -c ghr -n "__fish_is_arg_n 1" -a add -d "Add an existing repository into the ghr managed directory"
complete -c ghr -n "__fish_is_arg_n 1" -a browse -d "Browse a repository on web"
complete -c ghr -n "__fish_is_arg_n 1" -a cd -d "Change directory to one of the managed repositories (Shell extension required)"
complete -c ghr -n "__fish_is_arg_n 1" -a clone -d "Clones a Git repository to local"
complete -c ghr -n "__fish_is_arg_n 1" -a delete -d "Deletes a repository from local"
complete -c ghr -n "__fish_is_arg_n 1" -a init -d "Initialises a Git repository in local"
complete -c ghr -n "__fish_is_arg_n 1" -a list -d "Lists all managed repositories"
complete -c ghr -n "__fish_is_arg_n 1" -a open -d "Opens a repository in an application"
complete -c ghr -n "__fish_is_arg_n 1" -a browse -d "Browse a repository on web"
complete -c ghr -n "__fish_is_arg_n 1" -a path -d "Prints the path to root, owner, or a repository"
complete -c ghr -n "__fish_is_arg_n 1" -a profile -d "Manages profiles to use in repositories"
complete -c ghr -n "__fish_is_arg_n 1" -a shell -d "Writes a shell script to extend ghr features"
complete -c ghr -n "__fish_is_arg_n 1" -a sync -d "Sync repositories between your devices"
complete -c ghr -n "__fish_is_arg_n 1" -a version -d "Prints the version of this application"

# Complete the 2nd argument of add command using the file path
complete -c ghr -n "__fish_is_arg_n 2; and __fish_seen_subcommand_from add" -f

# Complete the 2nd argument of cd, delete, path, open, and browse commands using the repository list
complete -c ghr -n "__fish_is_arg_n 2; and __fish_seen_subcommand_from cd delete path open browse" -a "(ghr list)"
complete -c ghr -n "__fish_is_arg_n 2; and __fish_seen_subcommand_from browse cd delete path open" -a "(ghr list)"

# Complete the 3rd argument of open command using the known command list
complete -c ghr -n "__fish_is_arg_n 3; and __fish_seen_subcommand_from open" -a "(complete -C '')"
Expand All @@ -31,3 +36,7 @@ complete -c ghr -n "__fish_is_arg_n 2; and __fish_seen_subcommand_from profile"

# Complete the 3rd argument of profile list subcommand using the profile list
complete -c ghr -n "__fish_is_arg_n 3; and __fish_seen_subcommand_from profile; and __fish_seen_subcommand_from show apply" -a "(ghr profile list --short)"

# Complete subcommands of sync command with their description
complete -c ghr -n "__fish_is_arg_n 2; and __fish_seen_subcommand_from sync" -a dump -d "Dump remotes and the current ref of all repositories"
complete -c ghr -n "__fish_is_arg_n 2; and __fish_seen_subcommand_from sync" -a restore -d "Restore repositories from the dumped file"