Skip to content

Commit

Permalink
feat(issue): add options for naming linked branch
Browse files Browse the repository at this point in the history
Add environment variables that prepend info to branch names when they
are created and linked to the selected issue. Spaces in the variables
are removed.

- GH_FZF_BRANCH_PREFIX: a string at the beginning of the branch name
- GH_FZF_BRANCH_ADD_ISSUE_NUMBER: When non-empty, the issue number is
  added after the prefix (if specified), and the value of this
  environment variable is added after the number.

For example, the branch name will be "benelan/123-fix-bug" if you enter
"fix bug" when prompted and have the following variables set:

    export GH_FZF_BRANCH_PREFIX="$(
        git config --global github.user || echo "benelan"
     )/"
    export GH_FZF_BRANCH_ADD_ISSUE_NUMBER="-"

Note that spaces in the prompt's value are replaced with hyphens.
Another example:

    export GH_FZF_BRANCH_PREFIX="issue-"
    export GH_FZF_BRANCH_ADD_ISSUE_NUMBER=" "

This will result in the branch name "issue-123" if you press enter
without adding a value to the prompt, because spaces in the environment
variables are removed.
  • Loading branch information
benelan committed May 17, 2024
1 parent 9c484d8 commit f6f78e2
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions gh-fzf
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,13 @@ $global_binds
)+refresh-preview" \
--bind="enter:execute(gh issue edit {1} $repo_flag)+refresh-preview" \
--bind='alt-o:execute(
printf "Branch name for {1} (leave blank to use the default): ";
read -r branch;
gh issue develop {1} --checkout ${branch:+--name $branch} '"$repo_flag"'
prefix="$GH_FZF_BRANCH_PREFIX"
num="${GH_FZF_BRANCH_ADD_ISSUE_NUMBER:+{1}$GH_FZF_BRANCH_ADD_ISSUE_NUMBER}"
num=$(tr -d "#'\''" <<< ${num// /})
printf "Enter branch name for {1}: ${prefix}${num}";
read -r name;
branch="${prefix}${num}${name// /-}"
gh issue develop {1} --checkout ${branch:+--name "$branch"} '"$repo_flag"'
)+abort' \
--bind="alt-c:execute(gh issue comment {1} $repo_flag)+refresh-preview" \
--bind='alt-l:execute(
Expand Down

0 comments on commit f6f78e2

Please sign in to comment.