gh alias set
gh alias set <alias> <expansion> [flags]
定义一个单词,该单词在调用时会扩展为完整的 gh 命令。
扩展可以指定额外的参数和标志。如果扩展包含位置占位符,例如 $1
,则跟随别名的额外参数将被适当地插入。否则,额外参数将被追加到扩展的命令。
使用 -
作为扩展参数从标准输入读取扩展字符串。这对于在定义扩展时避免引用问题很有用。
如果扩展以 !
开头,或者如果给出了 --shell
,则扩展是一个 shell 表达式,将在调用别名时通过 sh
解释器进行评估。这允许通过管道和重定向链接多个命令。
选项
-
--clobber
- 覆盖相同名称的现有别名
-s
,--shell
- 声明一个别名为通过 shell 解释器传递
示例
# note: Command Prompt on Windows requires using double quotes for arguments
$ gh alias set pv 'pr view'
$ gh pv -w 123 #=> gh pr view -w 123
$ gh alias set bugs 'issue list --label=bugs'
$ gh bugs
$ gh alias set homework 'issue list --assignee @me'
$ gh homework
$ gh alias set 'issue mine' 'issue list --mention @me'
$ gh issue mine
$ gh alias set epicsBy 'issue list --author="$1" --label="epic"'
$ gh epicsBy vilmibm #=> gh issue list --author="vilmibm" --label="epic"
$ gh alias set --shell igrep 'gh issue list --label="$1" | grep "$2"'
$ gh igrep epic foo #=> gh issue list --label="epic" | grep "foo"