Skip to content
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ gh_list_dump.sql
gh_list_state.json
gh_list.db
.git-pad-github/
.git-pad/
51 changes: 51 additions & 0 deletions autocompletion.fish
Original file line number Diff line number Diff line change
@@ -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'
56 changes: 33 additions & 23 deletions install.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -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
fi