-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetup_bash.go
55 lines (47 loc) · 1.13 KB
/
setup_bash.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package main
import (
"fmt"
"os"
)
const BASH = `#! /bin/bash
: ${PROG:=$(basename ${BASH_SOURCE})}
_cli_bash_autocomplete() {
if [[ "${COMP_WORDS[0]}" != "source" ]]; then
local cur opts base
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
if [[ "$cur" == "-"* ]]; then
opts=$( ${COMP_WORDS[@]:0:$COMP_CWORD} ${cur} --generate-bash-completion )
else
opts=$( ${COMP_WORDS[@]:0:$COMP_CWORD} --generate-bash-completion )
fi
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
fi
}
complete -o bashdefault -o default -o nospace -F _cli_bash_autocomplete $PROG
unset PROG`
func setupBash() error {
err := write("/etc/bash_completion.d/nw", BASH, false)
if err != nil {
return err
}
err = write("/etc/bash_completion.d/narwhal", BASH, false)
if err != nil {
return err
}
fmt.Println("Please either restart your shell or run:")
fmt.Println("\tsource ~/.bashrc")
return nil
}
func tearDownBash() error {
err := os.Remove("/etc/bash_completion.d/nw")
if err != nil {
fmt.Println(err)
}
err = os.Remove("/etc/bash_completion.d/narwhal")
if err != nil {
fmt.Println(err)
}
return nil
}