Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Bug path completion chsh -s



On Aug 22,  9:08pm, Bart Schaefer wrote:
}
} Also, chsh has different syntax on different OS's:  On MacOS it's an
} alias for chpass; on Ubuntu it only has --help and --shell options
} (and their -h -s counterparts); on RHEL it has several options and
} uses -u instead of -h for --help, and adds -l for --list, both of
} which conflict with chpass on MacOs; and so on.  So "please fix" is
} a rather open-ended request.

Having done that research, I went ahead and created an _chsh that I
think covers most cases.  I don't have BSD handy to test with, but the
man page on MacOS claims it is using the BSD chpass.

} Maybe somebody else can remind me if there's an easier way to indicate
} to _arguments that all the arguments are mutually exclusive.

Of course there is, it's just (-).


diff --git a/Completion/Unix/Command/.distfiles b/Completion/Unix/Command/.distfiles
index fe810e1..35d81b2 100644
--- a/Completion/Unix/Command/.distfiles
+++ b/Completion/Unix/Command/.distfiles
@@ -29,6 +29,7 @@ _cdrecord
 _chkconfig
 _chmod
 _chown
+_chsh
 _clay
 _comm
 _compress
diff --git a/Completion/Unix/Command/_chsh b/Completion/Unix/Command/_chsh
new file mode 100644
index 0000000..97552e3
--- /dev/null
+++ b/Completion/Unix/Command/_chsh
@@ -0,0 +1,40 @@
+#compdef chsh chpass
+case $OSTYPE in
+(darwin*|*bsd*)
+  _arguments : \
+      '-s[Specify user login shell]:shell:(${(Z+Cn+)"$(</etc/shells)"})' \
+      "-l[Specify location of user]:node:" \
+      "-u[Specify authentication name]:auth user:" \
+      "1:user name:_users"
+  ;;
+(linux-gnu)
+  if { =chsh -v } >&/dev/null
+  then
+      local -a opts shells
+      shells=( $(=chsh -l) )
+      _arguments : \
+	  "(-)-s[Specify your login shell]:shell:($shells)" \
+	  "(-)--shell[Specify your login shell]:shell:($shells)" \
+	  "(-)-l[Print shells in /etc/shells]" \
+	  "(-)--list-shells[Print shells in /etc/shells]" \
+	  "(-)-u[Print a usage message and exit]" \
+	  "(-)--help[Print a usage message and exit]" \
+	  "(-)-v[Print version information and exit]" \
+	  "(-)--version[Print version information and exit]" \
+	  "1:user name:_users"
+      return
+  fi
+  # else fall through
+  ;&
+(*)
+  local s=''
+  # Use $s to cause all options to be treated as mutually exclusive
+  [[ $words[CURRENT-1] = -* ]] && s="(-)$words[CURRENT-1]"
+  # This fiddling with $s is a hack to cause "_arguments  : --" to use
+  # the /etc/shells listing for -s or --shell even when the description
+  # of that option has been pulled from the GNU --help output.
+  [[ $words[CURRENT-1] = (-s|--shell) ]] &&
+    s="$s"'[ ]:shell:(${(Z+Cn+)"$(</etc/shells)"})'
+  _arguments : $s "1:user name:_users" --
+  ;;
+esac
diff --git a/Completion/Unix/Type/_users b/Completion/Unix/Type/_users
index 5ab8dbc..3c8c702 100644
--- a/Completion/Unix/Type/_users
+++ b/Completion/Unix/Type/_users
@@ -1,4 +1,4 @@
-#compdef passwd groups userdel chage chfn chsh
+#compdef passwd groups userdel chage chfn
 
 local expl users
 



Messages sorted by: Reverse Date, Date, Thread, Author