File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -7,23 +7,30 @@ SRC=main.c args.c byte_array.c image.c util.c file.c generate_ascii.c generate_b
77OBJ =$(addprefix obj/, $(addsuffix .o, $(SRC ) ) )
88
99BIN =bin-graph
10+ COMPLETION =bin-graph-completion.bash
1011
1112PREFIX =/usr/local
1213BINDIR =$(PREFIX ) /bin
14+ COMPLETIONDIR =$(PREFIX ) /share/bash-completion/completions
1315
1416# -------------------------------------------------------------------------------
1517
16- .PHONY : all clean install
18+ .PHONY : all clean install install-bin install-completion
1719
1820all : $(BIN )
1921
2022clean :
2123 rm -f $(OBJ )
2224 rm -f $(BIN )
2325
24- install : $(BIN )
26+ install : install-bin install-completion
27+
28+ install-bin : $(BIN )
2529 install -D -m 755 $^ -t $(DESTDIR )$(BINDIR )
2630
31+ install-completion : $(COMPLETION )
32+ install -D -m 644 $^ $(DESTDIR )$(COMPLETIONDIR ) /$(BIN )
33+
2734# -------------------------------------------------------------------------------
2835
2936$(BIN ) : $(OBJ )
Original file line number Diff line number Diff line change 1+ #! /usr/bin/env bash
2+
3+ _bin_graph_completion () {
4+ local arg_opts nonarg_opts
5+ arg_opts=(
6+ -m --mode
7+ -w --width
8+ -z --zoom
9+ --block-size
10+ --offset-start --offset-end
11+ --output-format
12+ --transform-squares
13+ )
14+ nonarg_opts=(
15+ -h --help
16+ --list-modes
17+ --list-output-formats
18+ )
19+
20+ # If the previous option ('$3') is a redirector, show the default file
21+ # completion.
22+ if [[ " $3 " == ' 2>' || " $3 " == ' >' || " $3 " == ' <' ]]; then
23+ compopt -o bashdefault -o default
24+ return
25+ fi
26+
27+ # If the previous option expected an extra parameter, don't show completion.
28+ for arg in " ${arg_opts[@]} " ; do
29+ if [ " $3 " = " $arg " ]; then
30+ return
31+ fi
32+ done
33+
34+ if [[ " $2 " = -* ]]; then
35+ # If the current option ('$2') starts with a dash, return (in
36+ # '$COMPREPLY') the possible completions for the current option using
37+ # 'compgen'.
38+ mapfile -t COMPREPLY < <( compgen -W " ${arg_opts[*]} ${nonarg_opts[*]} " -- " $2 " )
39+ else
40+ # Otherwise, show the default file completion.
41+ compopt -o bashdefault -o default
42+ fi
43+ }
44+
45+ complete -F _bin_graph_completion bin-graph
You can’t perform that action at this time.
0 commit comments