Skip to content

Commit f6f78e2

Browse files
committed
feat(issue): add options for naming linked branch
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.
1 parent 9c484d8 commit f6f78e2

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

gh-fzf

+7-3
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,13 @@ $global_binds
203203
)+refresh-preview" \
204204
--bind="enter:execute(gh issue edit {1} $repo_flag)+refresh-preview" \
205205
--bind='alt-o:execute(
206-
printf "Branch name for {1} (leave blank to use the default): ";
207-
read -r branch;
208-
gh issue develop {1} --checkout ${branch:+--name $branch} '"$repo_flag"'
206+
prefix="$GH_FZF_BRANCH_PREFIX"
207+
num="${GH_FZF_BRANCH_ADD_ISSUE_NUMBER:+{1}$GH_FZF_BRANCH_ADD_ISSUE_NUMBER}"
208+
num=$(tr -d "#'\''" <<< ${num// /})
209+
printf "Enter branch name for {1}: ${prefix}${num}";
210+
read -r name;
211+
branch="${prefix}${num}${name// /-}"
212+
gh issue develop {1} --checkout ${branch:+--name "$branch"} '"$repo_flag"'
209213
)+abort' \
210214
--bind="alt-c:execute(gh issue comment {1} $repo_flag)+refresh-preview" \
211215
--bind='alt-l:execute(

0 commit comments

Comments
 (0)