From a3857ab280c3cbd4c97e0e3524fe2be069f7572a Mon Sep 17 00:00:00 2001 Message-Id: From: Mark Wooding Date: Thu, 3 May 2018 13:47:21 +0100 Subject: [PATCH] Makefile, dot/rcrc: Hack rc(1) profile for Plan 9 compatibility. Organization: Straylight/Edgeware From: Mark Wooding 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 | 10 +++++++++- dot/rcrc | 29 ++++++++++++++++------------- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/Makefile b/Makefile index 00d06e4..ea368f2 100644 --- 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 diff --git a/dot/rcrc b/dot/rcrc index 39d9435..adc607e 100644 --- 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 $* } } -- [mdw]