Skip to content

Commit

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

For more info, see `gh label list --help` and the readme:
https://github.com/benelan/gh-fzf#label
  • Loading branch information
benelan committed Mar 7, 2024
1 parent 09e402b commit abec1bd
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 2 deletions.
29 changes: 28 additions & 1 deletion 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)
- [`workflow`](#workflow)
- [`release`](#release)
- [`label`](#label)
- [`repo`](#repo)
- [`gist`](#gist)
- [Configuration](#configuration)
Expand Down Expand Up @@ -222,13 +223,38 @@ that can be used with any `gh fzf` command:
- `alt-p`: Filter the list, showing published releases
(i.e. excluding drafts)
- `alt-a`: Filter the list, showing releases in ascending order by release date
(defaults to descending order)
(defaults to descending)
- **Examples**:
- Filter the initial list to exclude drafts and pre-releases:
```sh
gh fzf release --exclude-drafts --exclude-pre-releases
```

### `label`

- **Usage**: `gh fzf label [flags]`
- **Aliases**: `labels`, `--label`, `--labels`
- **Flags**: See `gh label list --help` for available options
- **Keybindings**:
- `enter`: Print the name of the selected label
- `alt-n`: Edit the name of the selected label
(see `gh label edit --help`)
- `alt-d`: Edit the description of the selected label
(see `gh label edit --help`)
- `alt-c`: Edit the color of the selected label
(see `gh label edit --help`)
- `alt-X`: Delete the selected label
(see `gh label delete --help`)
- `alt-N`: Filter the list, sorting labels by name
(defaults to creation date)
- `alt-D`: Filter the list, showing labels in descending order
(defaults to ascending)
- **Examples**:
- Filter the initial list to sort by label name in descending order
```sh
gh fzf label --sort name --order desc
```

### `repo`

- **Usage**: `gh fzf repo [flags]`
Expand Down Expand Up @@ -322,6 +348,7 @@ When adding or modifying fzf keybindings:
- the `<number>` for the `issue` and `pr` commands
- the `<tag>` for the `release` command
- the `<id>` for the `gist` command
- the `<name>` for the `label` command
- Use `{-1}` in place of:
- the `<run-id>` for the `run` command
- the `<workflow-id>` for the `workflow` command
Expand Down
43 changes: 42 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.
workflow Search for and interact with GitHub Action workflows.
release Search for and interact with GitHub releases.
label Search for and interact with GitHub labels.
repo Search for and interact with GitHub repos.
gist Search for and interact with GitHub gists.
Expand Down Expand Up @@ -129,7 +130,7 @@ FZF_DEFAULT_OPTS='
# --------------------------------------------------------------------- {|}

default_cmd() {
FZF_DEFAULT_COMMAND="printf 'COMMAND\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n' issue pr run workflow release repo gist" \
FZF_DEFAULT_COMMAND="printf 'COMMAND\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n' issue pr run workflow release label repo gist" \
fzf \
--preview='GH_FORCE_TTY=$FZF_PREVIEW_COLUMNS gh help {}' \
--preview-window='right:75%,wrap' \
Expand Down Expand Up @@ -520,6 +521,45 @@ Filters > (alt-a: all)
--bind='alt-a:reload(eval "$FZF_DEFAULT_COMMAND --all")'
}

# --------------------------------------------------------------------- }}}
# Command > label {{{
# --------------------------------------------------------------------- {|}

label_cmd() {
label_header='Actions > (enter: print) (alt-n: edit name) (alt-d: edit description) (alt-c: edit color) (alt-X: delete)
> (ctrl-o: open url) (ctrl-r: reload)
Filters > (alt-N: sort by name) (alt-D: descending order)
'

FZF_DEFAULT_COMMAND="GH_FORCE_TTY=$gh_columns gh label list -L $GH_FZF_DEFAULT_LIMIT $*" \
fzf \
--no-preview \
--delimiter=' ' \
--header-lines=4 \
--header="$label_header" \
--bind="start:$on_start" \
--bind="enter:execute(printf {1})+abort" \
--bind='ctrl-o:execute-silent(gh label list --web)' \
--bind='alt-n:execute(
printf "Enter new label name: ";
read -r name;
[ -n "$name" ] && gh label edit {1} --name "$name"
)' \
--bind='alt-d:execute(
printf "Enter new label description: ";
read -r description;
[ -n "$description" ] && gh label edit {1} --description "$description"
)' \
--bind='alt-c:execute(
printf "Enter new label color: ";
read -r color;
[ -n "$color" ] && gh label edit {1} --color "$color"
)' \
--bind="alt-X:execute(gh label delete {1})" \
--bind='alt-N:reload(eval "$FZF_DEFAULT_COMMAND --sort name")' \
--bind='alt-D:reload(eval "$FZF_DEFAULT_COMMAND --order desc")' || true
}

# --------------------------------------------------------------------- }}}
# Parse arguments {{{
# --------------------------------------------------------------------- {|}
Expand Down Expand Up @@ -560,6 +600,7 @@ main() {
release | releases | --release | --releases) release_cmd "$@" ;;
gist | gists | --gist | --gists) gist_cmd "$@" ;;
workflow | workflows | --workflow | --workflows) workflow_cmd "$@" ;;
label | labels | --label | --labels) label_cmd "$@" ;;
v | V | -v | -V | version | --version) printf "%s\n" "$GH_FZF_VERSION" ;;
*) error "invalid command: \"$command\"" ;;
esac
Expand Down

0 comments on commit abec1bd

Please sign in to comment.