You are not logged in.

#1 2020-11-15 21:18:02

MountainX
Member
Registered: 2016-02-08
Posts: 371

How to add new command line option to genfstab?

I would like to test a locally modified version of genfstab from arch-install-scripts.git.

EDIT: this is what I ended up doing.

sudo pacman -Qi asciidoc #for a2x dependency
git clone https://git.archlinux.org/arch-install-scripts.git
cd arch-install-scripts/

edit genfstab.in to make my changes.
also edit completion/genfstab.bash

git diff genfstab.in
git diff completion/genfstab.bash
make

Now I have a modified genfstab to test.

EDIT 2: Are these commands required for my local testing?

# source genfstab.bash
# complete -F _genfstab genfstab

I don't have any experience working with bash completions (except as a user), but the changes I need look pretty simple...

diff --git a/completion/genfstab.bash b/completion/genfstab.bash
index 69506d9..e1aae2d 100644
--- a/completion/genfstab.bash
+++ b/completion/genfstab.bash
@@ -3,10 +3,10 @@ _genfstab() {
     local cur prev words cword
     _init_completion || return

-    local opts="-f -L -p -P -t -U -h"
+    local opts="-e -f -L -p -P -t -U -h"

     case ${prev} in
-        -f)
+        -f|-e)
             return 0
             ;;
         -t)

This shows my idea for the filter options. I'm sure it has flaws, but it does allow me to do stuff like this "./genfstab -e "nfs4" /path" which is what I was trying to achieve.

diff --git a/genfstab.in b/genfstab.in
index c626290..d8254dd 100644
--- a/genfstab.in
+++ b/genfstab.in
@@ -79,7 +79,8 @@ usage() {
 usage: ${0##*/} [options] root

   Options:
-    -f <filter>    Restrict output to mountpoints matching the prefix FILTER
+    -e <exclude>   Exclude mountpoints matching the pattern FILTER
+    -f <filter>    Include only mountpoints matching the pattern FILTER
     -L             Use labels for source identifiers (shortcut for -t LABEL)
     -p             Exclude pseudofs mounts (default behavior)
     -P             Include pseudofs mounts
@@ -100,7 +101,7 @@ if [[ -z $1 || $1 = @(-h|--help) ]]; then
   exit $(( $# ? 0 : 1 ))
 fi

-while getopts ':f:LPpt:U' flag; do
+while getopts ':e:f:LPpt:U' flag; do
   case $flag in
     L)
       bytag=LABEL
@@ -108,8 +109,11 @@ while getopts ':f:LPpt:U' flag; do
     U)
       bytag=UUID
       ;;
+    e)
+      excludefilter=$OPTARG
+      ;;
     f)
-      prefixfilter=$OPTARG
+      includefilter=$OPTARG
       ;;
     P)
       pseudofs=1
@@ -144,7 +148,8 @@ findmnt -Recvruno SOURCE,TARGET,FSTYPE,OPTIONS,FSROOT "$root" |
     continue
   fi

-  [[ $target = "$prefixfilter"* ]] || continue
+  [[ $src =~ "$excludefilter" || $target =~ "$excludefilter" || $fstype =~ "$excludefilter" ]] && continue
+  [[ $src =~ "$includefilter" || $target =~ "$includefilter" ]] || continue

   # default 5th and 6th columns
   dump=0 pass=2

Last edited by MountainX (2020-11-15 22:27:53)

Offline

Board footer

Powered by FluxBB