From 6a152aa6b47a889865f5395e2a4e00aa61a64d26 Mon Sep 17 00:00:00 2001 From: Brian Buller Date: Thu, 28 Jun 2018 17:05:53 -0500 Subject: [PATCH] Add Bash Completion Script --- README.md | 6 ++++++ emt-completion.bash | 3 +++ main.go | 6 +++++- 3 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 emt-completion.bash diff --git a/README.md b/README.md index 7ae1723..6d2d2d5 100644 --- a/README.md +++ b/README.md @@ -3,3 +3,9 @@ CLI Emojis Binaries: https://bullercodeworks.com/downloads/emt/ + +Included is a completion script for bash: +* `emt-completion.bash` + +Just put `emt` in your path, then source the completion script when you +fire up your shell (put a line in your bashrc or something) diff --git a/emt-completion.bash b/emt-completion.bash new file mode 100644 index 0000000..e91f025 --- /dev/null +++ b/emt-completion.bash @@ -0,0 +1,3 @@ +#/usr/bin/env bash +WORDLIST=`emt -completion-list` +complete -W "$WORDLIST" emt diff --git a/main.go b/main.go index db689ff..4ee5048 100644 --- a/main.go +++ b/main.go @@ -16,15 +16,19 @@ func main() { var getApprox bool var which string var matchWhich string + allEmoji := emoji.CodeMap() for _, v := range os.Args { if v == "-a" { getApprox = true + } else if v == "-completion-list" { + for k, _ := range allEmoji { + fmt.Print(strings.Trim(k, ":"), " ") + } } else { which = v } } - allEmoji := emoji.CodeMap() if !strings.HasPrefix(which, ":") && !strings.HasSuffix(which, ":") { matchWhich = ":" + which + ":" }