Add Bash Completion Script

This commit is contained in:
Brian Buller 2018-06-28 17:05:53 -05:00
parent 6b3b39ad40
commit 6a152aa6b4
3 changed files with 14 additions and 1 deletions

View File

@ -3,3 +3,9 @@ CLI Emojis
Binaries: Binaries:
https://bullercodeworks.com/downloads/emt/ 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)

3
emt-completion.bash Normal file
View File

@ -0,0 +1,3 @@
#/usr/bin/env bash
WORDLIST=`emt -completion-list`
complete -W "$WORDLIST" emt

View File

@ -16,15 +16,19 @@ func main() {
var getApprox bool var getApprox bool
var which string var which string
var matchWhich string var matchWhich string
allEmoji := emoji.CodeMap()
for _, v := range os.Args { for _, v := range os.Args {
if v == "-a" { if v == "-a" {
getApprox = true getApprox = true
} else if v == "-completion-list" {
for k, _ := range allEmoji {
fmt.Print(strings.Trim(k, ":"), " ")
}
} else { } else {
which = v which = v
} }
} }
allEmoji := emoji.CodeMap()
if !strings.HasPrefix(which, ":") && !strings.HasSuffix(which, ":") { if !strings.HasPrefix(which, ":") && !strings.HasSuffix(which, ":") {
matchWhich = ":" + which + ":" matchWhich = ":" + which + ":"
} }