Remove 'selector-16' which the macos emoji picker inserts, and handle it being present

This commit is contained in:
vlad 2021-12-20 22:48:10 -08:00
parent c06ca5dad2
commit c7e09adba2
10 changed files with 130 additions and 65 deletions

View File

@ -52,4 +52,4 @@ _verify-prerequisites() {
fi fi
} }
source ⚡ source ⚡

4
go
View File

@ -1,7 +1,7 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -euo pipefail set -euo pipefail
test() { ⚡test() {
_help-line "Run all the tests" "$@" _help-line "Run all the tests" "$@"
exit=0 exit=0
for test in test/test*; do for test in test/test*; do
@ -10,4 +10,4 @@ set -euo pipefail
exit $exit exit $exit
} }
source ⚡ source ⚡

View File

@ -1,9 +1,9 @@
# ⚡-runner: the minimal task runner you've been missing in your life # ⚡-runner: the minimal task runner you've been missing in your life
-runner is a language-agnostic task runner in the category of tools such as `make`, `grunt`, `gradle`, `leiningen`, etc. It has a single, widely available dependency: bash. ⚡-runner is a language-agnostic task runner in the category of tools such as `make`, `grunt`, `gradle`, `leiningen`, etc. It has a single, widely available dependency: bash.
It's intent is to provide your shell scripts with the syntactic sugar they crave to make them more presentable, and more manageable. It's intent is to provide your shell scripts with the syntactic sugar they crave to make them more presentable, and more manageable.
# Why have you done this? # Why have you done this?
The main reason ⚡-runner was born, was because I'm a huge fan of [go scripts](https://blog.thepete.net/blog/2014/03/28/_-attributes-of-an-amazing-dev-toolchain/). I find myself including one in nearly every repo I make. I've also started finding myself copy-pasting a WHOLE bunch of helper functions across them. These scripts are always in bash to make them easily usable by everyone on a team, regardless of their operating system of choice. I've also found myself using similar patterns for other scripts I have, which do maybe more than a single thing but maybe less than a full application would warrant. The main reason ⚡-runner was born, was because I'm a huge fan of [go scripts](https://blog.thepete.net/blog/2014/03/28/_-attributes-of-an-amazing-dev-toolchain/). I find myself including one in nearly every repo I make. I've also started finding myself copy-pasting a WHOLE bunch of helper functions across them. These scripts are always in bash to make them easily usable by everyone on a team, regardless of their operating system of choice. I've also found myself using similar patterns for other scripts I have, which do maybe more than a single thing but maybe less than a full application would warrant.
# Usage # Usage
Download the runner, chuck it into your repo, and source it from a shell script! Download the runner, chuck it into your repo, and source it from a shell script!
@ -12,18 +12,18 @@ Download the runner, chuck it into your repo, and source it from a shell script!
# Now it's time for some documentation-driven development! (a.k.a. usage examples) # Now it's time for some documentation-driven development! (a.k.a. usage examples)
a.k.a. Literally none of this works. a.k.a. Literally none of this works.
## Hello ⚡ ## Hello ⚡
As is tradition: As is tradition:
```bash ```bash
$ echo ' $ echo '
#!/usr/bin/env bash #!/usr/bin/env bash
hello() { ⚡hello() {
_help-line "Say hello!" _help-line "Say hello!"
echo Hello, world! echo Hello, world!
} }
source ⚡ source ⚡
' > go && chmod +x go ' > go && chmod +x go
$ ./go hello $ ./go hello
Hello, world! Hello, world!
@ -41,35 +41,35 @@ Look! It's like a task runner!
#!/usr/bin/env bash #!/usr/bin/env bash
cd $(dirname $0) cd $(dirname $0)
build() { ⚡build() {
echo "echo hi" > .generated/potato echo "echo hi" > .generated/potato
chmod +x .generated/potato chmod +x .generated/potato
} }
run() { ⚡run() {
build ⚡build
.generated/potato "$@" .generated/potato "$@"
} }
check() { ⚡check() {
build ⚡build
shellcheck .generated/potato shellcheck .generated/potato
} }
test() { ⚡test() {
build ⚡build
[ "$(.generated/potato)" == "hi" ] [ "$(.generated/potato)" == "hi" ]
} }
clean() { ⚡clean() {
rm -rf .generated rm -rf .generated
} }
source ⚡ source ⚡
``` ```
## It's just bash! ## It's just bash!
Do whatever you need, just define a ⚡function or two as the interface Do whatever you need, just define a ⚡function or two as the interface
```bash ```bash
#!/usr/bin/env bash #!/usr/bin/env bash
@ -82,13 +82,13 @@ router-curl() {
curl -s -b $cookie_jar_path -c $cookie_jar_path -X POST "http://192.168.0.1/cgi-bin/luci/;stok=${STOK:-}/$path" "$@" curl -s -b $cookie_jar_path -c $cookie_jar_path -X POST "http://192.168.0.1/cgi-bin/luci/;stok=${STOK:-}/$path" "$@"
} }
connected-devices() { ⚡connected-devices() {
_help-line "Show devices connected to router" _help-line "Show devices connected to router"
STOK=$(router-curl login?form=login --data-raw "operation=login&password=$encrypted_password"| jq -r .data.stok ) STOK=$(router-curl login?form=login --data-raw "operation=login&password=$encrypted_password"| jq -r .data.stok )
router-curl admin/status?form=all | jq '.data | [.access_devices_wired, .access_devices_wireless_guest, .access_devices_wireless_host] | flatten' router-curl admin/status?form=all | jq '.data | [.access_devices_wired, .access_devices_wireless_guest, .access_devices_wireless_host] | flatten'
} }
source ⚡ source ⚡
``` ```
# More sugar # More sugar
@ -97,15 +97,15 @@ source ⚡️
$ echo ' $ echo '
#!/usr/bin/env bash #!/usr/bin/env bash
good() { ⚡good() {
_good-message + Good Message _good-message + Good Message
} }
bad() { ⚡bad() {
_bad-message - Bad Message _bad-message - Bad Message
} }
source ⚡ source ⚡
' > go && chmod +x go ' > go && chmod +x go
$ ./go good $ ./go good
+ Good message + Good message
@ -122,11 +122,11 @@ _verify-prerequisites() {
docker ps &> /dev/null || (echo 'Not enough docker'; exit 1) docker ps &> /dev/null || (echo 'Not enough docker'; exit 1)
} }
ubuntu() { ⚡ubuntu() {
docker run -ti ubuntu docker run -ti ubuntu
} }
source ⚡ source ⚡
' > go && chmod +x go ' > go && chmod +x go
$ ./go ubuntu $ ./go ubuntu
Not enough docker Not enough docker
@ -147,11 +147,11 @@ kubectlw() {
-d https://dl.k8s.io/release/VERSION/bin/darwin/amd64/kubectl -d https://dl.k8s.io/release/VERSION/bin/darwin/amd64/kubectl
} }
kubectl-version() { ⚡kubectl-version() {
kubectlw version kubectlw version
} }
source ⚡ source ⚡
' > go && chmod +x go ' > go && chmod +x go
$ ./go kubectl-version $ ./go kubectl-version
Client Version: version.Info{Major:"1", Minor:"19", GitVersion:"v1.19.4", GitCommit:"d360454c9bcd1634cf4cc52d1867af5491dc9c5f", GitTreeState:"clean", BuildDate:"2020-11-11T13:17:17Z", GoVersion:"go1.15.2", Compiler:"gc", Platform:"darwin/amd64"} Client Version: version.Info{Major:"1", Minor:"19", GitVersion:"v1.19.4", GitCommit:"d360454c9bcd1634cf4cc52d1867af5491dc9c5f", GitTreeState:"clean", BuildDate:"2020-11-11T13:17:17Z", GoVersion:"go1.15.2", Compiler:"gc", Platform:"darwin/amd64"}
@ -160,16 +160,16 @@ The connection to the server localhost:8080 was refused - did you specify the ri
``` ```
# Appendix # Appendix
This is where I would put the full list of helpers ⚡-runner provides IF I HAD ONE This is where I would put the full list of helpers ⚡-runner provides IF I HAD ONE
# FAQ # FAQ
## How do I type ⚡? ## How do I type ⚡?
Below this line are a number of options. Go down the list until you find one that works for you. Below this line are a number of options. Go down the list until you find one that works for you.
- ^⌘Space on macos opens the emoji picker. Search for 'lightning' - ^⌘Space on macos opens the emoji picker. Search for 'lightning'
- ⊞Win + . on windows opens the emoji picker. Search for 'lightning' - ⊞Win + . on windows opens the emoji picker. Search for 'lightning'
- ctrl + . within gnome opens the emoji picker. Search for 'lightning' (can someone confirm?) - ctrl + . within gnome opens the emoji picker. Search for 'lightning' (can someone confirm?)
- Super + . within KDE opens the emoji picker. Search for 'lightning' (can someone confirm?) - Super + . within KDE opens the emoji picker. Search for 'lightning' (can someone confirm?)
- Copy and paste this: ⚡ - Copy and paste this: ⚡
- Use your favorite web search engine to search for 'lightning emoji', copy paste from there. - Use your favorite web search engine to search for 'lightning emoji', copy paste from there.
## Why bash? ## Why bash?
Because I like it. Because I like it.

11
test.sh Executable file
View File

@ -0,0 +1,11 @@
#!/usr/bin/env bash
foo() {
echo stupid
}
⚡bar() {
echo not stupid
}
source

View File

@ -70,5 +70,4 @@ if [ ! -f $SHUNIT_PATH ]; then (
) )
fi fi
source $SHUNIT_PATH source $SHUNIT_PATH

View File

@ -4,7 +4,7 @@ testUsageIsShownWhenNoCommandIsSpecified() {
echo ' echo '
#!/usr/bin/env bash #!/usr/bin/env bash
' > go ' > go
echo "source $REPO_ROOT/⚡" >> go echo "source $REPO_ROOT/⚡" >> go
chmod +x go chmod +x go
try ./go try ./go
@ -14,9 +14,9 @@ testUsageIsShownWhenNoCommandIsSpecified() {
testHelpSubcommandCannotBeOverridden() { testHelpSubcommandCannotBeOverridden() {
echo ' echo '
#!/usr/bin/env bash #!/usr/bin/env bash
help() { echo "ah hah hah" ; } ⚡help() { echo "ah hah hah" ; }
' > go ' > go
echo "source $REPO_ROOT/⚡" >> go echo "source $REPO_ROOT/⚡" >> go
chmod +x go chmod +x go
try ./go help try ./go help
@ -28,7 +28,7 @@ testHelpIncludesInvocationInstructions() {
echo ' echo '
#!/usr/bin/env bash #!/usr/bin/env bash
' > $SCRIPT_NAME ' > $SCRIPT_NAME
echo "source $REPO_ROOT/⚡" >> $SCRIPT_NAME echo "source $REPO_ROOT/⚡" >> $SCRIPT_NAME
chmod +x $SCRIPT_NAME chmod +x $SCRIPT_NAME
try ./$SCRIPT_NAME help try ./$SCRIPT_NAME help
@ -38,12 +38,12 @@ testHelpIncludesInvocationInstructions() {
testHelpListsAllAvailableLightningCommands() { testHelpListsAllAvailableLightningCommands() {
echo ' echo '
#!/usr/bin/env bash #!/usr/bin/env bash
foo() { echo "ah hah hah" ; } ⚡foo() { echo "ah hah hah" ; }
bar() { echo "ah hah hah" ; } ⚡bar() { echo "ah hah hah" ; }
baz() { echo "ah hah hah" ; } ⚡baz() { echo "ah hah hah" ; }
potato() { echo "ah hah hah" ; } ⚡potato() { echo "ah hah hah" ; }
' > go ' > go
echo "source $REPO_ROOT/⚡" >> go echo "source $REPO_ROOT/⚡" >> go
chmod +x go chmod +x go
try ./go help try ./go help
@ -58,13 +58,13 @@ testHelpLinesFromDefinedCommandsAreShown() {
echo ' echo '
#!/usr/bin/env bash #!/usr/bin/env bash
hello() { ⚡hello() {
_help-line "Say Hello" "$@" _help-line "Say Hello" "$@"
echo "Hello, World!" ; echo "Hello, World!" ;
} }
' > go ' > go
echo "source $REPO_ROOT/⚡" >> go echo "source $REPO_ROOT/⚡" >> go
chmod +x go chmod +x go
try ./go try ./go
@ -75,10 +75,10 @@ testHelpDoesNotExecuteFunctionsWithNoHelpLine() {
echo ' echo '
#!/usr/bin/env bash #!/usr/bin/env bash
hello() { echo "Hello, World!" ; } ⚡hello() { echo "Hello, World!" ; }
' > go ' > go
echo "source $REPO_ROOT/⚡" >> go echo "source $REPO_ROOT/⚡" >> go
chmod +x go chmod +x go
try ./go try ./go
@ -89,14 +89,14 @@ testLightningShouldNotBeIncludedInSubcommandNames() {
echo ' echo '
#!/usr/bin/env bash #!/usr/bin/env bash
hello() { echo "Hello, World!" ; } ⚡hello() { echo "Hello, World!" ; }
' > go ' > go
echo "source $REPO_ROOT/⚡" >> go echo "source $REPO_ROOT/⚡" >> go
chmod +x go chmod +x go
try ./go try ./go
assertNotContains "$STDOUT" "⚡hello" assertNotContains "$STDOUT" "⚡hello"
} }
source $(dirname $0)/runner source $(dirname $0)/runner

View File

@ -5,10 +5,10 @@ testShouldBailIfRequirementsNotMet() {
#!/usr/bin/env bash #!/usr/bin/env bash
_verify-prerequisites() { false; } _verify-prerequisites() { false; }
hello() { echo "Hello, World!" ; } ⚡hello() { echo "Hello, World!" ; }
' > go ' > go
echo "source $REPO_ROOT/⚡" >> go echo "source $REPO_ROOT/⚡" >> go
chmod +x go chmod +x go
try ./go try ./go
@ -21,10 +21,10 @@ testShouldNotBailWhenPrereqsAreAllGood() {
#!/usr/bin/env bash #!/usr/bin/env bash
_verify-prerequisites() { true; } _verify-prerequisites() { true; }
hello() { echo "Hello, World!" ; } ⚡hello() { echo "Hello, World!" ; }
' > go ' > go
echo "source $REPO_ROOT/⚡" >> go echo "source $REPO_ROOT/⚡" >> go
chmod +x go chmod +x go
try ./go try ./go

View File

@ -4,14 +4,60 @@ testDefiningALightningFunctionWorks() {
echo ' echo '
#!/usr/bin/env bash #!/usr/bin/env bash
hello() { echo "Hello, World!" ; } ⚡hello() { echo "Hello, World!" ; }
' > go ' > go
echo "source $REPO_ROOT/⚡" >> go echo "source $REPO_ROOT/⚡" >> go
chmod +x go chmod +x go
try ./go hello try ./go hello
assertEquals "Hello, World!" "$STDOUT" assertEquals "Hello, World!" "$STDOUT"
} }
testReferingToALightningFunctionWorks() {
echo '
#!/usr/bin/env bash
⚡goodbye() { echo Good Bye.; }
⚡hello() { echo "Hello, World!" ; ⚡goodbye ; }
' > go
echo "source $REPO_ROOT/⚡" >> go
chmod +x go
try ./go hello
assertContains "$STDOUT" "Hello, World!"
assertContains "$STDOUT" "Good Bye."
}
testDefiningALightningFunctionWorksWithSelector16() {
echo '
#!/usr/bin/env bash
hello() { echo "Hello, World!" ; }
' > go
echo "source $REPO_ROOT/⚡" >> go
chmod +x go
try ./go hello
assertEquals "Hello, World!" "$STDOUT"
}
testReferingToALightningFunctionWorksWithSelector16() {
echo '
#!/usr/bin/env bash
goodbye() { echo Good Bye.; }
hello() { echo "Hello, World!" ; ⚡goodbye ; }
' > go
echo "source $REPO_ROOT/⚡" >> go
chmod +x go
try ./go hello
assertContains "$STDOUT" "Hello, World!"
assertContains "$STDOUT" "Good Bye."
}
source $(dirname $0)/runner source $(dirname $0)/runner

View File

@ -4,12 +4,12 @@ testGoodMessageShouldBeGreen() {
echo ' echo '
#!/usr/bin/env bash #!/usr/bin/env bash
hello() { ⚡hello() {
_good-message "hello" _good-message "hello"
} }
' > go ' > go
echo "source $REPO_ROOT/⚡" >> go echo "source $REPO_ROOT/⚡" >> go
chmod +x go chmod +x go
try ./go hello try ./go hello
@ -20,12 +20,12 @@ testBadMessageShouldBeRed() {
echo ' echo '
#!/usr/bin/env bash #!/usr/bin/env bash
hello() { ⚡hello() {
_bad-message "hello" _bad-message "hello"
} }
' > go ' > go
echo "source $REPO_ROOT/⚡" >> go echo "source $REPO_ROOT/⚡" >> go
chmod +x go chmod +x go
try ./go hello try ./go hello

View File

@ -1,21 +1,30 @@
#!/usr/bin/env bash #!/usr/bin/env bash
main() { main() {
if [[ $(type -t "⚡️$1") == "function" ]]; then redefine-functions-defined-with-selector-16
⚡️$1 if [[ $(type -t "⚡$1") == "function" ]]; then
⚡$1
else else
help ⚡help
fi fi
} }
help() { redefine-functions-defined-with-selector-16() {
for function in $(compgen -c $(printf "⚡\uFE0F")); do
original_definition="$(typeset -f $function)"
eval "${original_definition//$(printf "⚡\uFE0F")/⚡}"
unset $function
done
}
⚡help() {
_help-line "Show this list" "$@" _help-line "Show this list" "$@"
echo Usage: "$0" SUBCOMMAND echo Usage: "$0" SUBCOMMAND
echo echo
echo "Available subcommands:" echo "Available subcommands:"
for subcommand in $(_subcommands); do for subcommand in $(_subcommands); do
if [[ $(type ⚡️$subcommand) =~ _help-line ]]; then if [[ $(type ⚡$subcommand) =~ _help-line ]]; then
printf "\t%-20s - %s\n" "$subcommand" "$(⚡️$subcommand help-line)" printf "\t%-20s - %s\n" "$subcommand" "$(⚡$subcommand help-line)"
else else
printf "\t%-20s\n" $subcommand printf "\t%-20s\n" $subcommand
fi fi
@ -23,7 +32,7 @@ main() {
} }
_subcommands() { _subcommands() {
compgen -c ⚡ | cut -c3- compgen -c ⚡ | cut -c2-
} }
_help-line() { _help-line() {