Last active
April 14, 2024 20:09
-
-
Save ardnew/497fc3ed4864fb392d4cf38249d2f1ab to your computer and use it in GitHub Desktop.
bash functions to abbreviate github/gh-copilot commands
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/opt/bash/bin/bash | |
if ghbin=$( type -P gh ); then | |
copilot="github/gh-copilot" | |
if "${ghbin}" extension list 2>&1 | cut -s -f2 | grep -q "^${copilot}$"; then | |
function ? { | |
[[ ${#} -gt 0 ]] || set -- --help | |
case ${1} in | |
git) set -- --target git "${@:2}" ;; | |
gh|github) set -- --target gh "${@:2}" ;; | |
--*) ;; | |
sh|shell|bash) set -- "${@:2}" ;& | |
*) set -- --target shell "${@}" ;; | |
esac | |
"${ghbin}" copilot suggest "${@}" | |
} | |
function ?? { "${ghbin}" copilot explain "${@}" ; } | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Important
The command
?
is effectively an alias forgh copilot suggest
, and the command??
is effectively an alias forgh copilot explain
.Given no other arguments, each will print their respective
--help
flag.For
?
(i.e.,suggest
), if the first word is a recognized target, or a similar, related word (e.g.,sh
andbash
will both use targetshell
, andgithub
will use targetgh
), then the target flag is inserted with recognized argument prior the remaining command line arguments.If the first word is not a recognized target, then
--target shell
is inserted automatically.For
??
(i.e.,explain
), all arguments are forwarded through verbatim.Tip
Examples: