Skip to content

Commit

Permalink
feat: add gist command (#12)
Browse files Browse the repository at this point in the history
Add a command for finding and viewing Github gists.

For more info, see `gh gist list --help` and the readme:
https://github.com/benelan/gh-fzf#gist
  • Loading branch information
benelan committed Mar 6, 2024
1 parent 604c79c commit 13ac32c
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 4 deletions.
30 changes: 27 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ An fzf wrapper around the GitHub CLI.
- [`run`](#run)
- [`repo`](#repo)
- [`release`](#release)
- [`gist`](#gist)
- [Configuration](#configuration)
- [Related projects](#related-projects)

Expand Down Expand Up @@ -239,6 +240,26 @@ that can be used with any `gh fzf` command:
gh fzf release --exclude-drafts --exclude-pre-releases
```

### `gist`

- **Usage**: `gh fzf gist [flags]`
- **Aliases**: `gists`, `--gist`, `--gists`
- **Flags**: See `gh gist list --help` for available options
- **Keybindings**:
- `enter`: Edit the selected gist
(see `gh gist edit --help`)
- `alt-c`: Clone the selected gist to the current directory
(see `gh gist clone --help`)
- `alt-X`: Delete the selected gist
(see `gh gist delete --help`)
- `alt-s`: Filter the list, showing only secret gists
- `alt-p`: Filter the list, showing only public gists
- **Examples**:
- Filter the initial list to only show public gists (excluding secret ones):
```sh
gh fzf gist --public
```

## Configuration

Environment variables are used to configure different options in `gh-fzf`.
Expand Down Expand Up @@ -274,9 +295,12 @@ aliases:

When adding or modifying fzf keybindings:

- Use `{1}` in place of the `<number>` for the `issue`/`pr` commands and in
place of the `<tag-name>` for the `release` command.
- Use `{-1}` in place of the `<run-id>` for the `run` command.
- Use `{1}` in place of:
- the `<number>` for the `issue` and `pr` commands
- the `<tag>` for the `release` command
- the `<id>` for the `gist` command
- Use `{-1}` in place of:
- the `<run-id>` for the `run` command

For a list of the fzf options shared by all `gh-fzf` commands, see the
[source code](https://github.com/benelan/gh-fzf/blob/c455e3034f49da1ae81c26779de2419fda87e4a8/gh-fzf#L145-L165).
Expand Down
29 changes: 28 additions & 1 deletion gh-fzf
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ Core Commands:
run Search for and interact with GitHub Action runs.
repo Search for and interact with GitHub repos.
release Search for and interact with GitHub releases.
gist Search for and interact with GitHub gists.
See \`gh <command> list --help\` for the flag options.
Expand Down Expand Up @@ -127,7 +128,7 @@ FZF_DEFAULT_OPTS='
# --------------------------------------------------------------------- {|}

default_cmd() {
FZF_DEFAULT_COMMAND="printf 'COMMAND\n%s\n%s\n%s\n%s\n%s\n' 'issue' 'pr' 'run' 'repo' 'release'" \
FZF_DEFAULT_COMMAND="printf 'COMMAND\n%s\n%s\n%s\n%s\n%s\n%s\n' 'issue' 'pr' 'run' 'repo' 'release' 'gist'" \
fzf \
--preview='GH_FORCE_TTY=$FZF_PREVIEW_COLUMNS gh help {}' \
--preview-window='right:75%,wrap' \
Expand Down Expand Up @@ -469,6 +470,31 @@ Filters > (alt-s: stable) (alt-p: published) (alt-a: ascending)
--bind='alt-a:reload(eval "$FZF_DEFAULT_COMMAND --order asc")'
}

# --------------------------------------------------------------------- }}}
# Command > gist {{{
# --------------------------------------------------------------------- {|}

gist_cmd() {
gist_header='Actions > (enter: edit) (alt-c: clone) (alt-X: delete)
> (ctrl-o: open url) (ctrl-y: copy url) (ctrl-r: reload)
Filters > (alt-p: public) (alt-s: secret)
'

FZF_DEFAULT_COMMAND="GH_FORCE_TTY=$gh_columns gh gist list -L $GH_FZF_DEFAULT_LIMIT $*" \
fzf \
--preview='GH_FORCE_TTY=$FZF_PREVIEW_COLUMNS gh gist view {1}' \
--header="$gist_header" \
--bind="start:$on_start" \
--bind='ctrl-o:execute-silent(gh gist view --web {1})' \
--bind="ctrl-y:execute-silent(echo https://gist.github.com/$(gh api user -q .login)/{1} | $GH_FZF_COPY_CMD)" \
--bind='enter:execute(gh gist edit {1})' \
--bind='alt-c:execute(gh gist clone {1})' \
--bind="alt-X:execute(gh gist delete {1})" \
--bind='alt-p:reload(eval "$FZF_DEFAULT_COMMAND --public")' \
--bind='alt-s:reload(eval "$FZF_DEFAULT_COMMAND --secret")'
}

# --------------------------------------------------------------------- }}}
# Parse arguments {{{
# --------------------------------------------------------------------- {|}
Expand Down Expand Up @@ -507,6 +533,7 @@ main() {
r | -r | run | runs | --run | --runs) run_cmd "$@" ;;
repo | repos | --repo | --repos) repo_cmd "$@" ;;
release | releases | --release | --releases) release_cmd "$@" ;;
gist | gists | --gist | --gists) gist_cmd "$@" ;;
v | V | -v | -V | version | --version) printf "%s\n" "$GH_FZF_VERSION" ;;
*) error "invalid command: \"$command\"" ;;
esac
Expand Down

0 comments on commit 13ac32c

Please sign in to comment.