aboutsummaryrefslogtreecommitdiffgithub
diff options
context:
space:
mode:
authorAustin Adams <git@austinjadams.com>2015-09-12 18:19:58 -0400
committerAustin Adams <git@austinjadams.com>2015-09-12 18:19:58 -0400
commita197cbce85fc23383ea94c5245df7a5147492617 (patch)
tree87753b66c3266dfda102d031fbb15da8612248a7
parentde522bea76293ac3ad149ef2e0dd6a70fbaa2e04 (diff)
downloadnsdo-a197cbce85fc23383ea94c5245df7a5147492617.tar.gz
nsdo-a197cbce85fc23383ea94c5245df7a5147492617.tar.xz
add bash completion, tweak makefile
also fixed a type in the manpage
-rw-r--r--.gitignore4
-rw-r--r--Makefile11
-rw-r--r--README.md4
-rw-r--r--bash_completion/nsdo20
-rw-r--r--nsdo.12
5 files changed, 33 insertions, 8 deletions
diff --git a/.gitignore b/.gitignore
index ff5d630..8f95be3 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,3 @@
-nsdo
-nsdo.1.gz
+/nsdo
+/nsdo.1.gz
.*.sw?
diff --git a/Makefile b/Makefile
index 390723a..7705b6e 100644
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,9 @@
CFLAGS ?= -Wall -Werror -O3
+# if you're building a system package, you should probably set these to
+# /usr, /usr/share/bash-completion/completions, and your package dir
PREFIX ?= /usr/local
+BASH_COMPLETION_DIR ?= /etc/bash_completion.d
+DESTDIR ?=
PROG = nsdo
MANSECTION = 1
@@ -12,14 +16,15 @@ README = README.md
all: $(PROG) $(MANPAGEGZ) $(README)
install: $(PROG) $(MANPAGEGZ)
- install -Dm6755 $< $(PREFIX)/bin/$<
- install -Dm644 $(word 2,$^) $(PREFIX)/share/man/man$(MANSECTION)/$(word 2,$^)
+ install -Dm4755 $< $(DESTDIR)$(PREFIX)/bin/$<
+ install -Dm644 $(word 2,$^) $(DESTDIR)$(PREFIX)/share/man/man$(MANSECTION)/$(word 2,$^)
+ install -Dm644 bash_completion/$(PROG) $(DESTDIR)$(BASH_COMPLETION_DIR)/$(PROG)
clean:
rm -fv $(PROG) $(MANPAGEGZ) $(README)
$(MANPAGEGZ): $(MANPAGE)
- gzip --best -k $<
+ gzip --best -f -k $<
$(README): readme.head $(MANPAGE)
{ \
diff --git a/README.md b/README.md
index 5a26649..a4e59db 100644
--- a/README.md
+++ b/README.md
@@ -64,8 +64,8 @@ manpage
DESCRIPTION
Execute command as the current user/group in namespace, a
- Linux network namespace set up with iproute2 (see ip-netns
- (8)).
+ Linux network namespace set up with iproute2 (see ip-
+ netns(8)).
By default, iproute2 places network namespaces in
/var/run/netns/, so nsdo searces for namespaces there
diff --git a/bash_completion/nsdo b/bash_completion/nsdo
new file mode 100644
index 0000000..c3e32f1
--- /dev/null
+++ b/bash_completion/nsdo
@@ -0,0 +1,20 @@
+# nsdo(1) completion -*- shell-script -*-
+
+_nsdo()
+{
+ local cur prev words cword
+ _init_completion || return
+
+ if [[ $COMP_CWORD -eq 1 ]]; then
+ compopt -o filenames
+
+ # assume that the filenames in /var/run/netns don't contain
+ # newlines(!)
+ local IFS=$'\n'
+ COMPREPLY=( $(compgen -W "$(ip netns list)" -- "$cur") )
+ else
+ _command_offset 2
+ fi
+} && complete -F _nsdo nsdo
+
+# ex: ts=4 sw=4 et filetype=sh
diff --git a/nsdo.1 b/nsdo.1
index a2a3753..d212e99 100644
--- a/nsdo.1
+++ b/nsdo.1
@@ -6,7 +6,7 @@ nsdo \- run a command in a network namespace
.I namespace command
[\fIargs\fR ...]
.SH DESCRIPTION
-Execute \fIcommand\fR as the current user/group in \fInamespace\fR, a Linux network namespace set up with \fBiproute2\fR (see \fBip-netns (8)\fR).
+Execute \fIcommand\fR as the current user/group in \fInamespace\fR, a Linux network namespace set up with \fBiproute2\fR (see \fBip-netns(8)\fR).
.PP
By default, \fBiproute2\fR places network namespaces in /var/run/netns/, so \fBnsdo\fR searces for namespaces there (including \fInamespace\fR).
To prevent \fIcommand\fR from easily escaping the namespace 'jail,' \fBnsdo\fR will exit if the current namespace exists in that directory.