chiark / gitweb /
Makefile, dot/rcrc: Hack rc(1) profile for Plan 9 compatibility.
authorMark Wooding <mdw@distorted.org.uk>
Thu, 3 May 2018 12:47:21 +0000 (13:47 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Thu, 3 May 2018 12:51:53 +0000 (13:51 +0100)
Annoyingly, the native-Linux rc(1) port doesn't accept the same syntax
as Plan 9 From User Space.

  * Plan 9 requires braces around command substitutions, so `{hostname}
    rather than `hostname.

  * Plan 9 doesn't have here-strings, so use echo instead.

  * Plan 9 is pickier about concatenating unset variables, so set them
    empty explicitly.

  * Plan 9 has a bizarre `if not' syntax rather than allowing `else'
    clauses.

This last is the most annoying difference, since the only thing
acceptable to both implementations is to repeat the condition.

Prefer the Plan 9 version throughout, and seddery the script to make the
native port version.  Fortunately they end up in different places;
otherwise we'd be really stuffed.

Makefile
dot/rcrc

index 00d06e4f2d13f79d4a3e3413aab5ca4f6f882824..ea368f25728e0ec080c1a4ecbdfee1f15598bfbc 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -150,7 +150,7 @@ SCRIPTLINKS         += update-buildable-branch
 
 ## Shells.
 DOTLINKS               += .profile .shell-rc .shell-logout
-DOTLINKS               += .shrc .rcrc
+DOTLINKS               += .shrc
 DOTLINKS               += .zprofile .zshrc .zlogout .zshenv
 DOTLINKS               += .bash_profile .bash_completion .bash_logout
 DOTLINKS               += .bashrc .inputrc
@@ -159,6 +159,14 @@ DOTLINKS           += .bashrc .inputrc
 .bash_logout_SRC        = shell-logout
 .zlogout_SRC            = shell-logout
 
+## The Plan 9 `rc' shell.  This needs special hacking, because the Linux port
+## and Plan 9 From User Space have incompatible syntax.
+DOTLINKS               += lib/profile
+lib/profile_SRC                 = rcrc
+all:: $(HOME)/.rcrc
+$(HOME)/.rcrc: dot/rcrc
+       $(call v_tag,SED)sed 's/; if not/else/' $< >$@.new && mv $@.new $@
+
 ## Git.
 DOTSUBST               += .gitconfig
 SCRIPTLINKS            += git-copyright-dates
index 39d9435b215f9ba60f258b25695c61706d53573a..adc607e96b6703802c5df933c4c3bd84e058c867 100644 (file)
--- a/dot/rcrc
+++ b/dot/rcrc
@@ -4,42 +4,45 @@
 ###--------------------------------------------------------------------------
 ### Prompt machinery.
 
-host = `hostname
+host = `{hostname}
 
 if (~ $TERM linux* screen* xterm* vt100* eterm*) {
   bold = `{tput bold} unbold = `{tput sgr0}
-} else {
+}; if not {
   bold = '' unbold = ''
 }
 
 if (~ `{id -u} 0) {
-  left = `{iconv -f utf8 -t //translit <<< «}
-  right = `{iconv -f utf8 -t //translit <<< »}
-} else {
+  left = `{echo « | iconv -f utf8 -t //translit}
+  right = `{echo » | iconv -f utf8 -t //translit}
+}; if not {
   u = `{id -un}
   if (~ $u mdw mwooding) {
     u = '' left = '[' right = ']'
-  } else {
+  }; if not {
     u = $u^@ left = '{' right = '}'
   }
-  if (~ $__mdw_tty `tty) {
+  if (~ $__mdw_tty `{tty}) {
     left = '<' right = '>'
-  } else {
-    __mdw_tty = `tty
+  }; if not {
+    __mdw_tty = `{tty}
   }
 }
 
 if (~ $#SSH_CLIENT 0 && ! ~ $__mdw_sechost $host) {
   sec_l = '(' sec_r = ')'
+}; if not {
+  sec_l = '' sec_r = ''
 }
 
 fn prompt {
-  cwd = `pwd
+  cwd = `{pwd}
   if (~ $cwd $home $home/*) {
-    cwd = `{sed 's:^' ^ $home ^':~:' <<< $cwd}
+    cwd = `{echo $cwd | sed 's:^' ^ $home ^':~:'}
   }
   prompt = ($bold$left$sec_l$u$host$sec_r^' '^$cwd$right$unbold '')
 }
+prompt
 
 ###--------------------------------------------------------------------------
 ### Convenient aliases.
@@ -54,7 +57,7 @@ fn @ { ssh $* }
 fn ls {
   if (test -t 1) {
     builtin ls $LS_OPTIONS '--color=auto' $*
-  } else {
+  }; if not {
     builtin ls $*
   }
 }
@@ -63,7 +66,7 @@ fn greplike {
   grep = $1; shift
   if (test -t 1) {
     builtin $grep '--color=always' $* | mdw-pager
-  } else {
+  }; if not {
     builtin grep $*
   }
 }