zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-workers@zsh.org
Subject: Re: Bug path completion chsh -s
Date: Sat, 23 Aug 2014 12:31:17 -0700	[thread overview]
Message-ID: <140823123117.ZM23674@torch.brasslantern.com> (raw)
In-Reply-To: <140822210846.ZM22535@torch.brasslantern.com>

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
 


  reply	other threads:[~2014-08-23 19:30 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-21 22:40 qcd
2014-08-23  4:08 ` Bart Schaefer
2014-08-23 19:31   ` Bart Schaefer [this message]
2014-08-25 15:37     ` Jun T.
2014-08-24  4:38   ` Mikael Magnusson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=140823123117.ZM23674@torch.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).