Skip to content

Commit

Permalink
inotifywatch: New completion, common with inotifywait
Browse files Browse the repository at this point in the history
  • Loading branch information
scop committed Jan 12, 2019
1 parent cfa6432 commit 2aa57d1
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 9 deletions.
1 change: 1 addition & 0 deletions completions/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ ifdown
ifquery
ifstatus
import
inotifywatch
insmod.static
iperf3
javac
Expand Down
5 changes: 5 additions & 0 deletions completions/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,7 @@ CLEANFILES = \
ifquery \
ifstatus \
import \
inotifywatch \
insmod.static \
iperf3 \
javac \
Expand Down Expand Up @@ -866,6 +867,10 @@ symlinks: $(targetdir) $(DATA)
rm -f $(targetdir)/$$file && \
$(LN_S) info $(targetdir)/$$file ; \
done
for file in inotifywatch ; do \
rm -f $(targetdir)/$$file && \
$(LN_S) inotifywait $(targetdir)/$$file ; \
done
for file in insmod.static ; do \
rm -f $(targetdir)/$$file && \
$(LN_S) insmod $(targetdir)/$$file ; \
Expand Down
28 changes: 19 additions & 9 deletions completions/inotifywait
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
# bash completion for inotifywait(1) -*- shell-script -*-
# bash completion for inotifywait(1) and inotifywatch(1) -*- shell-script -*-

_inotifywait_events()
{
# Expecting line with "Events:", followed by ones starting with one
# tab. Word following the tab is event name, others are line
# wrapped explanations.
COMPREPLY+=( $( compgen -W "$( $1 --help 2>/dev/null | \
sed -e '/^Events:/,/^[^'$'\t'']/!d' \
-ne 's/^'$'\t''\([^ '$'\t'']\{1,\}\)[ '$'\t''].*/\1/p' )" \
-- "$cur" ) )
}

_inotifywait()
{
Expand All @@ -14,13 +25,12 @@ _inotifywait()
return
;;
--event|-!(-*)e)
# Expecting line with "Events:", followed by ones starting with one
# tab. Word following the tab is event name, others are line
# wrapped explanations.
COMPREPLY=( $( compgen -W "$( $1 --help 2>/dev/null | \
sed -e '/^Events:/,/^[^'$'\t'']/!d' \
-ne 's/^'$'\t''\([^ '$'\t'']\{1,\}\)[ '$'\t''].*/\1/p' )" \
-- "$cur" ) )
_inotifywait_events "$1"
return
;;
--ascending|--descending)
COMPREPLY=( $( compgen -W 'total' -- "$cur" ) )
_inotifywait_events "$1"
return
;;
esac
Expand All @@ -32,6 +42,6 @@ _inotifywait()

_filedir
} &&
complete -F _inotifywait inotifywait
complete -F _inotifywait inotifywait inotifywatch

# ex: filetype=sh
1 change: 1 addition & 0 deletions test/t/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ EXTRA_DIST = \
test_info.py \
test_inject.py \
test_inotifywait.py \
test_inotifywatch.py \
test_insmod.py \
test_installpkg.py \
test_interdiff.py \
Expand Down
16 changes: 16 additions & 0 deletions test/t/test_inotifywatch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import pytest


class TestInotifywatch:

@pytest.mark.complete("inotifywatch ")
def test_1(self, completion):
assert completion.list

@pytest.mark.complete("inotifywatch --")
def test_2(self, completion):
assert completion.list

@pytest.mark.complete("inotifywatch -e ")
def test_3(self, completion):
assert len(completion.list) > 1

0 comments on commit 2aa57d1

Please sign in to comment.