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

Re: off topic



On Fri, 9 Dec 2016 19:24:06 +0000
Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx> wrote:
>     % env -i ZDOTDIR=$(mktemp -d) zsh
>     This is the Z Shell configuration function for new users,
>     zsh-newuser-install.
>     ⋮
>     (2)  Populate your /tmp/tmp.Z4bUNG8Gz5/.zshrc with the configuration recommended
>          by the system administrator and exit (you will need to edit
>          the file by hand, if so desired).
>     
>     --- Type one of the keys in parentheses --- 
> 
> Typing "2" creates a .zshrc with reasonable default settings, and drops
> the user to the prompt; no further menu choices.  The catch is that that
> check is hardcoded to inspect /etc/zsh/newuser.zshrc.recommended; that
> is, it ignores configure's --prefix.
> 
> So if we could make that check honour @PREFIX@, and ship a "recommended
> zshrc" that is less minimal than the default no-zshrc behaviour...
> I think that'd be a good step forward.

At the time there was a reason why newuser stuff used a fixed path
rather than tracking every version of the package, but not necessarily a
good one --- since the vast majority of users now will be receiving
things via a distribution it doesn't really apply.

My experience with recommended settings in previous threads (the last
one petered out some time ago now) is much like Gladstone's with the
Irish Question --- every time you think you're getting close, they
change the question(*).  But if you or anyone wants to pursue this further,
which I will happily support in the distribution, you might want
something like the following (untested --- and in particular untested
with out-of-tree configure which might make a difference).

pws

(*) You'll need to add "1066 and all that" to the search for
[de?]mystification on the subject.

commit 463a58ded82d3371b969bf9ee1b04814464d91bd
Author: Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
Date:   Fri Dec 9 21:24:37 2016 +0000

    Make recommended zshrc location configurable.

diff --git a/Functions/Newuser/zsh-newuser-install b/Functions/Newuser/zsh-newuser-install
index e4028fd..f639b6f 100644
--- a/Functions/Newuser/zsh-newuser-install
+++ b/Functions/Newuser/zsh-newuser-install
@@ -9,11 +9,29 @@ setopt extendedglob nonomatch warncreateglobal
 
 # How the function will be referred to.
 local myname=zsh-newuser-install
+integer force
+
+if [[ $1 = -f ]]; then
+  (( force = 1 ))
+  shift
+fi
+if [[ $1 = - || $1 == -- ]]; then
+  shift
+fi
+local zshrc_rec=/etc/zsh/newuser.zshrc.recommended
+if [[ -n $1 ]]; then
+  if [[ $1 = /* ]]; then
+    zshrc_rec=$1
+  else
+    print "Usage: $0 [ -f ] [ /path/to/newuser.zshrc.recommened ]" >&2
+    return 1
+  fi
+fi
 
 # Quick test not requiring any setting up.
 # Don't run if we're root.  (These variables are provided by the shell.)
 if (( EUID == 0 || UID == 0 )); then
-  if [[ $1 = -f ]]; then
+  if (( force )); then
     print -r "$myname: won't run as root.  Read the manual." >&2
   fi
   return 1
@@ -96,7 +114,7 @@ fi
 # if this really is a new user this probably isn't the right
 # time for screeds of explanation.
 if [[ ! -w $zd ]]; then
-  if [[ $1 = -f ]]; then
+  if (( force )); then
     print -r "$myname: can't write to $zdmsg." >&2
   fi
   return 1
@@ -104,7 +122,7 @@ fi
 
 # Don't run unless we can talk to the user.
 if [[ ! -t 0 || ! -t 1 ]]; then
-  if [[ $1 = -f ]]; then
+  if (( force )); then
     print -r "$myname: can only be used interactively." >&2
   fi
   return 1
@@ -115,7 +133,7 @@ if (( ${LINES:-0} < 15 || ${COLUMNS:-0} < 72 )); then
   return 1
 fi
 
-if [[ $1 != -f ]]; then
+if (( ! force )); then
   # The zsh/newuser module already tests for the following, so this test only
   # triggers if zsh-newuser-install is run by hand.
   if [[ -e $zd/.zshenv || -e $zd/.zprofile || \
@@ -934,7 +952,7 @@ fi
 
 
 # skip initial screen if the function was deliberately run by the user.
-if [[ $1 != -f ]]; then
+if (( ! force )); then
   clear
   print -r "This is the Z Shell configuration function for new users,
 $myname.
@@ -954,7 +972,7 @@ You can:
   print -r "
 (1)  Continue to the main menu.
 "
-  if [[ -f /etc/zsh/newuser.zshrc.recommended ]]; then
+  if [[ -f $zshrc_rec ]]; then
     print -r "(2)  Populate your $zdmsg/.zshrc with the configuration recommended
      by the system administrator and exit (you will need to edit
      the file by hand, if so desired).
@@ -978,14 +996,14 @@ You can:
     ;;
 
     (2)
-    cp /etc/zsh/newuser.zshrc.recommended $zd/.zshrc
+    cp $zshrc_rec $zd/.zshrc
     source $zd/.zshrc
     return 0
     ;;
 
     (*)
     print -r "Aborting."
-    if [[ $1 != -f ]]; then
+    if (( ! force )); then
       print "\
 The function will be run again next time.  To prevent this, execute:
   touch $zdmsg/.zshrc"
@@ -1036,7 +1054,7 @@ ${install_state[options]:+  ($install_state[options].)}
 (a)  Abort all settings and start from scratch.  Note this will overwrite
      any settings from $myname already in the startup file.
      It will not alter any of your other settings, however."
-  if [[ $1 = -f ]]; then
+  if (( force )); then
     print -r "
 (q)  Quit and do nothing else."
   else
@@ -1078,7 +1096,7 @@ ${install_state[options]:+  ($install_state[options].)}
     elif [[ ! -f $zd/.zshrc ]]; then
       print -r $msg >$zd/.zshrc
     fi
-    if [[ $1 != -f ]]; then
+    if (( force )); then
       print -r "The function will not be run in future, but you can run
 it yourself as follows:
   autoload -Uz $myname
diff --git a/Scripts/.gitignore b/Scripts/.gitignore
new file mode 100644
index 0000000..c889ba7
--- /dev/null
+++ b/Scripts/.gitignore
@@ -0,0 +1 @@
+newuser
diff --git a/Scripts/newuser b/Scripts/newuser
deleted file mode 100644
index b5d7421..0000000
--- a/Scripts/newuser
+++ /dev/null
@@ -1,8 +0,0 @@
-# zsh script sourced at startup when a user is found to have
-# no startup files.  See the documentation for the zsh/newuser
-# module in zshmodules(1).
-
-if functions zsh-newuser-install >/dev/null 2>&1 ||
-   autoload -U +X zsh-newuser-install; then
-   zsh-newuser-install
-fi
diff --git a/Scripts/newuser.in b/Scripts/newuser.in
new file mode 100644
index 0000000..678d115
--- /dev/null
+++ b/Scripts/newuser.in
@@ -0,0 +1,13 @@
+# zsh script sourced at startup when a user is found to have
+# no startup files.  See the documentation for the zsh/newuser
+# module in zshmodules(1).
+
+zshrc_rec=@zshrc_rec@
+if [[ -z $zshrc_rec ]]; then
+   prefix=@prefix@
+   zshrc_rec=@sysconfdir@/zsh/newuser.zshrc.recommended
+fi
+if functions zsh-newuser-install >/dev/null 2>&1 ||
+   autoload -U +X zsh-newuser-install; then
+   zsh-newuser-install $zshrc_rec
+fi
diff --git a/configure.ac b/configure.ac
index 920c2fc..55d3acd 100644
--- a/configure.ac
+++ b/configure.ac
@@ -237,11 +237,22 @@ if test "x$zlogout" != xno; then
   AC_DEFINE_UNQUOTED(GLOBAL_ZLOGOUT, "$zlogout")
 fi
 
+AC_ARG_ENABLE(zshrc-rec,
+AC_HELP_STRING([-enable-zshrc-rec=FILE], [the full pathname of a recommended zshrc file for new users]),
+[zshrc_rec="$enableval"],
+[if test "x$etcdir" = xno; then
+  zshrc_rec=no
+else
+  zshrc_rec="$etcdir/zsh/newuser.zshrc.recommended"
+fi])
+dnl zshrc_rec is only used by a script and is not needed in the source.
+
 AC_SUBST(zshenv)dnl
 AC_SUBST(zshrc)dnl
 AC_SUBST(zprofile)dnl
 AC_SUBST(zlogin)dnl
 AC_SUBST(zlogout)dnl
+AC_SUBST(zshrc_rec)dnl
 
 dnl Do you want dynamically loaded binary modules.
 ifdef([dynamic],[undefine([dynamic])])dnl
@@ -3283,7 +3294,7 @@ AC_SUBST_FILE(DEFS_MK)dnl
 AC_SUBST_FILE(VERSION_MK)dnl
 
 AC_CONFIG_FILES(Config/defs.mk Makefile Doc/Makefile Etc/Makefile \
-Src/Makefile Test/Makefile)
+Src/Makefile Test/Makefile Scripts/newuser)
 AC_CONFIG_COMMANDS([config.modules], [. ./config.modules.sh])
 AC_CONFIG_COMMANDS([stamp-h], [echo >stamp-h])
 



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