diff --git a/.gitignore b/.gitignore index 40b2e45..a3a8b61 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ gh_list_dump.sql gh_list_state.json gh_list.db .git-pad-github/ +.git-pad/ diff --git a/autocompletion.fish b/autocompletion.fish new file mode 100644 index 0000000..c981889 --- /dev/null +++ b/autocompletion.fish @@ -0,0 +1,51 @@ +function __fish_git_pad_command + set -l cmd (commandline -pxc) + test (count $cmd) -gt 1 + and contains -- $cmd[2] $argv +end + +function __fish_git_pad_needs_command + test (count (commandline -pxc)) -eq 1 +end + +function __fish_git_pad_issues + set -l pad_dir (string join "/" (dirname (git rev-parse --path-format=absolute --git-common-dir)) ".git-pad/issues") + + test -d "$pad_dir" + or return + + for f in (grep -l "status: \(open\|in-progress\)" $pad_dir/*.md) + set -l issue (string match -r -g "$pad_dir/(.*)\\.md\$" $f) + set -l desc (grep -m 1 '^title:' $f | string replace -m 1 "title: " "" | string shorten -m 35) + + printf "%s\t%s\n" $issue $desc + end +end + + +# No files expansion +complete -c git-pad --no-files + +# Simple commands +complete -c git-pad -n __fish_git_pad_needs_command -a init -x -d 'Initialize a new pad' +complete -c git-pad -n __fish_git_pad_needs_command -a status -x -d 'Show status' +complete -c git-pad -n __fish_git_pad_needs_command -a commit -x -d 'Commit changes' +complete -c git-pad -n __fish_git_pad_needs_command -a log -x -d 'Show log' +complete -c git-pad -n __fish_git_pad_needs_command -a list -x -d 'List issues' +complete -c git-pad -n __fish_git_pad_needs_command -a search -x -d 'Search issues' +complete -c git-pad -n __fish_git_pad_needs_command -a remove -x -d 'Remove an issue' +complete -c git-pad -n __fish_git_pad_needs_command -a clone -x -d 'Clone a pad' +complete -c git-pad -n __fish_git_pad_needs_command -a track -x -d 'Track an issue' +complete -c git-pad -n __fish_git_pad_needs_command -a remote -x -d 'Manage remotes' +complete -c git-pad -n __fish_git_pad_needs_command -a push -x -d 'Push changes' +complete -c git-pad -n __fish_git_pad_needs_command -a pull -x -d 'Pull changes' +complete -c git-pad -n __fish_git_pad_needs_command -a fetch -x -d 'Fetch changes' +complete -c git-pad -n __fish_git_pad_needs_command -a merge -x -d 'Merge changes' +complete -c git-pad -n __fish_git_pad_needs_command -a version -x -d 'Show version' + +# Comments with issue expansion +complete -c git-pad -n __fish_git_pad_needs_command -a edit -x -d 'Edit an issue' +complete -c git-pad -n '__fish_git_pad_command edit' -a '(__fish_git_pad_issues)' -x -d Issue + +complete -c git-pad -n __fish_git_pad_needs_command -a comment -x -d 'Add a comment' +complete -c git-pad -n __fish_git_pad_needs_command -a show -x -d 'Show an issue' diff --git a/install.sh b/install.sh old mode 100644 new mode 100755 index d7c0d0f..c89a93d --- a/install.sh +++ b/install.sh @@ -1,49 +1,59 @@ -#!/usr/bin/env bash +#!/usr/bin/env sh # shellcheck disable=SC2016 -if [ ! -f "git-pad" ] || { [ ! -f "autocompletion.bash" ] && [ ! -f "autocompletion.zsh" ]; } ; then +if [ ! -f "git-pad" ] || { [ ! -f "autocompletion.bash" ] && [ ! -f "autocompletion.zsh" ] && [ ! -f "autocompletion.fish" ]; } ; then echo '!E: Not in git-pad directory'; exit 1 fi -# On Windows/Git Bash, $SHELL may be unset or a Windows path -# so detect the shell via version variables instead -if [[ -n "${ZSH_VERSION:-}" ]]; then - shell_name="zsh" -elif [[ -n "${BASH_VERSION:-}" ]]; then - shell_name="bash" +if [ $# -eq 0 ]; then + # On Windows/Git Bash, $SHELL may be unset or a Windows path + # so detect the shell via version variables instead + if [ -n "${ZSH_VERSION:-}" ]; then + exec /usr/bin/env sh $0 zsh; + elif [ -n "${BASH_VERSION:-}" ]; then + exec /usr/bin/env sh $0 bash; + else + exec /usr/bin/env sh $0 "$(basename "${SHELL:-unknown}")"; + fi else - shell_name="$(basename "${SHELL:-unknown}")" + shell_name=$1 fi # On Windows, $HOME may be unset -if [[ -z "${HOME:-}" ]]; then +if [ -z "${HOME:-}" ]; then HOME="$(cd ~ && pwd)" fi +# Start the validation and installation +id="## git-pad" + case "$shell_name" in - bash) - rc="$HOME/.bashrc" + bash | zsh) + rc="$HOME/.${shell_name}rc" + block=' -## git-pad +'"$id"' PATH=$PATH:'"$PWD"' export PATH -. '"$PWD"'/autocompletion.bash' +. '"$PWD"'/autocompletion.'"$shell_name" ;; - zsh) - rc="$HOME/.zshrc" + + fish) + ln -s "$PWD/autocompletion.fish" "$HOME/.config/fish/completions/git-pad.fish" + rc="$HOME/.config/fish/config.fish" + block=' -## git-pad -PATH=$PATH:'"$PWD"' -export PATH -. '"$PWD"'/autocompletion.zsh' +'"$id"' +fish_add_path '"$PWD" ;; + *) echo "Unsupported shell: $shell_name"; exit 1 ;; esac -if grep -q '## git-pad' "$rc" 2>/dev/null; then +if grep -q "$id" "$rc" 2>/dev/null; then echo '!W: Looks like it is already installed' echo '--------------------------------------' - grep -C 5 '## git-pad' "$rc" + grep -C 5 "$id" "$rc" else echo "$block" >> "$rc" && echo "Installed successfully. Restart your shell." -fi \ No newline at end of file +fi