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
}
source ⚡
source ⚡

4
go
View File

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

View File

@ -1,9 +1,9 @@
# ⚡-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: 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.
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?
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
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)
a.k.a. Literally none of this works.
## Hello ⚡
## Hello ⚡
As is tradition:
```bash
$ echo '
#!/usr/bin/env bash
hello() {
⚡hello() {
_help-line "Say hello!"
echo Hello, world!
}
source ⚡
source ⚡
' > go && chmod +x go
$ ./go hello
Hello, world!
@ -41,35 +41,35 @@ Look! It's like a task runner!
#!/usr/bin/env bash
cd $(dirname $0)
build() {
⚡build() {
echo "echo hi" > .generated/potato
chmod +x .generated/potato
}
run() {
build
⚡run() {
⚡build
.generated/potato "$@"
}
check() {
build
⚡check() {
⚡build
shellcheck .generated/potato
}
test() {
build
⚡test() {
⚡build
[ "$(.generated/potato)" == "hi" ]
}
clean() {
⚡clean() {
rm -rf .generated
}
source ⚡
source ⚡
```
## 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
#!/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" "$@"
}
connected-devices() {
⚡connected-devices() {
_help-line "Show devices connected to router"
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'
}
source ⚡
source ⚡
```
# More sugar
@ -97,15 +97,15 @@ source ⚡️
$ echo '
#!/usr/bin/env bash
good() {
⚡good() {
_good-message + Good Message
}
bad() {
⚡bad() {
_bad-message - Bad Message
}
source ⚡
source ⚡
' > go && chmod +x go
$ ./go good
+ Good message
@ -122,11 +122,11 @@ _verify-prerequisites() {
docker ps &> /dev/null || (echo 'Not enough docker'; exit 1)
}
ubuntu() {
⚡ubuntu() {
docker run -ti ubuntu
}
source ⚡
source ⚡
' > go && chmod +x go
$ ./go ubuntu
Not enough docker
@ -147,11 +147,11 @@ kubectlw() {
-d https://dl.k8s.io/release/VERSION/bin/darwin/amd64/kubectl
}
kubectl-version() {
⚡kubectl-version() {
kubectlw version
}
source ⚡
source ⚡
' > go && chmod +x go
$ ./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"}
@ -160,16 +160,16 @@ The connection to the server localhost:8080 was refused - did you specify the ri
```
# 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
## 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.
- ^⌘Space on macos 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?)
- 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.
## Why bash?
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
source $SHUNIT_PATH

View File

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

View File

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

View File

@ -4,14 +4,60 @@ testDefiningALightningFunctionWorks() {
echo '
#!/usr/bin/env bash
hello() { echo "Hello, World!" ; }
⚡hello() { echo "Hello, World!" ; }
' > go
echo "source $REPO_ROOT/⚡" >> go
echo "source $REPO_ROOT/⚡" >> go
chmod +x go
try ./go hello
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

View File

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

View File

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