[arch-projects] [INITSCRIPTS][PATCH 1/6] Improve coloring on light and transparent term
This patch improve coloring in light and transparent term. It uses tput if available \033 are remplaced by \e Signed-off-by: Sebastien Luttringer <seblu@seblu.net> --- functions | 49 +++++++++++++++++++++++++++++-------------------- rc.sysinit | 4 ++-- 2 files changed, 31 insertions(+), 22 deletions(-) diff --git a/functions b/functions index fd0928e..500ec7c 100644 --- a/functions +++ b/functions @@ -49,28 +49,37 @@ else export LANG=C fi -# colors: -if [[ $USECOLOR = YES || $USECOLOR = yes ]]; then - C_MAIN="\033[1;37;40m" # main text - - C_OTHER="\033[1;34;40m" # prefix & brackets - C_SEPARATOR="\033[1;30;40m" # separator - - C_BUSY="\033[0;36;40m" # busy - C_FAIL="\033[1;31;40m" # failed - C_DONE="\033[1;37;40m" # completed - C_BKGD="\033[1;35;40m" # backgrounded - - C_H1="\033[1;37;40m" # highlight text 1 - C_H2="\033[1;36;40m" # highlight text 2 - - C_CLEAR="\033[1;0m" +# set colors +if [[ $USECOLOR =~ yes|YES ]]; then + if /bin/tput setaf 0 &>/dev/null; then + C_CLEAR="$(tput sgr0)" # clear text + C_MAIN="${C_CLEAR}$(/bin/tput bold)" # main text + C_OTHER="${C_MAIN}$(/bin/tput setaf 4)" # prefix & brackets + C_SEPARATOR="${C_MAIN}$(/bin/tput setaf 0)" # separator + C_BUSY="${C_CLEAR}$(/bin/tput setaf 6)" # busy + C_FAIL="${C_MAIN}$(/bin/tput setaf 1)" # failed + C_DONE="${C_MAIN}" # completed + C_BKGD="${C_MAIN}$(/bin/tput setaf 5)" # backgrounded + C_H1="${C_MAIN}" # highlight text 1 + C_H2="${C_MAIN}$(/bin/tput setaf 6)" # highlight text 2 + else + C_CLEAR="\e[m" # clear text + C_MAIN="\e[;1m" # main text + C_OTHER="\e[1;34m" # prefix & brackets + C_SEPARATOR="\e[1;30m" # separator + C_BUSY="\e[;36m" # busy + C_FAIL="\e[1;31m" # failed + C_DONE="${C_MAIN}" # completed + C_BKGD="\e[1;35m" # backgrounded + C_H1="${$C_MAIN}" # highlight text 1 + C_H2="\e[1;36m" # highlight text 2 + fi fi if [[ -t 1 ]]; then - SAVE_POSITION="\033[s" - RESTORE_POSITION="\033[u" - DEL_TEXT="\033[$(($STAT_COL+4))G" + SAVE_POSITION="\e[s" + RESTORE_POSITION="\e[u" + DEL_TEXT="\e[$(($STAT_COL+4))G" else SAVE_POSITION="" RESTORE_POSITION="" @@ -360,7 +369,7 @@ set_consolefont() { stat_fail elif [[ $CONSOLEMAP ]]; then cat <<"EOF" >>/etc/profile.d/locale.sh -if [ "$CONSOLE" = "" -a "$TERM" = "linux" -a -t 1 ]; then printf "\033(K"; fi +if [ "$CONSOLE" = "" -a "$TERM" = "linux" -a -t 1 ]; then printf "\e(K"; fi EOF stat_done else diff --git a/rc.sysinit b/rc.sysinit index dc4be58..7b2cdfe 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -352,7 +352,7 @@ if [[ ${LOCALE,,} =~ utf ]]; then # but also when user has set vt.default_utf8=0 but LOCALE is *.UTF-8. for i in /dev/tty[0-9]*; do /usr/bin/kbd_mode -u < ${i} - printf "\033%%G" > ${i} + printf "\e%%G" > ${i} done echo 1 > /sys/module/vt/parameters/default_utf8 stat_done @@ -362,7 +362,7 @@ else # make non-UTF-8 consoles work on 2.6.24 and newer kernels for i in /dev/tty[0-9]*; do /usr/bin/kbd_mode -a < ${i} - printf "\033%%@" > ${i} + printf "\e%%@" > ${i} done echo 0 > /sys/module/vt/parameters/default_utf8 stat_done -- Sebastien "Seblu" Luttringer
- print daemon text with C_CLEAR and not C_MAIN - print rc name based on $0 (in case of renaming) Signed-off-by: Sebastien Luttringer <seblu@seblu.net> --- rc | 13 +++++++------ 1 files changed, 7 insertions(+), 6 deletions(-) diff --git a/rc b/rc index 743d86b..02c2b6c 100755 --- a/rc +++ b/rc @@ -4,12 +4,13 @@ . /etc/rc.d/functions usage() { - cat >&2 << EOF -usage: rc action daemon ... + local name=${0##*/} + cat >&2 << EOF +usage: $name action daemon ... -e.g: rc list - rc help - rc start sshd gpm +e.g: $name list + $name help + $name start sshd gpm EOF exit 1 } @@ -37,7 +38,7 @@ case $1 in else printf "${C_OTHER}[${C_FAIL} ${C_OTHER}]" fi - printf " ${C_MAIN}$d${C_CLEAR}\n" + printf " ${C_CLEAR}$d\n" done ;; *) -- Sebastien "Seblu" Luttringer
To avoid conflict with plan9 rc shell we need to rename our rc. Original name come from debian invoke-rc.d, shortened into rc. Signed-off-by: Sebastien Luttringer <seblu@seblu.net> --- Makefile | 2 +- rc | 61 ------------------------------------------------------------- rc.d | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 62 deletions(-) delete mode 100755 rc create mode 100755 rc.d diff --git a/Makefile b/Makefile index d3a1824..6923840 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,7 @@ install: minilogd installdirs install -m755 -t $(DESTDIR)/etc rc.local rc.local.shutdown rc.multi rc.shutdown rc.single rc.sysinit install -m755 -t $(DESTDIR)/etc/cron.hourly adjtime install -m755 -t $(DESTDIR)/etc/rc.d functions hwclock network netfs - install -m755 -t $(DESTDIR)/sbin minilogd rc + install -m755 -t $(DESTDIR)/sbin minilogd rc.d clean: rm -f minilogd minilogd.o diff --git a/rc b/rc deleted file mode 100755 index 02c2b6c..0000000 --- a/rc +++ /dev/null @@ -1,61 +0,0 @@ -#!/bin/bash - -. /etc/rc.conf -. /etc/rc.d/functions - -usage() { - local name=${0##*/} - cat >&2 << EOF -usage: $name action daemon ... - -e.g: $name list - $name help - $name start sshd gpm -EOF - exit 1 -} - -(( $# < 1 )) && usage - -declare -i ret=0 -case $1 in - help) - usage - ;; - list) - cd /etc/rc.d/ - for d in *; do - have_daemon "$d" || continue - # print running / stopped satus - if ! ck_daemon "$d"; then - printf "${C_OTHER}[${C_DONE}STARTED${C_OTHER}]" - else - printf "${C_OTHER}[${C_FAIL}STOPPED${C_OTHER}]" - fi - # print auto / manual status - if ! ck_autostart "$d"; then - printf "${C_OTHER}[${C_DONE}AUTO${C_OTHER}]" - else - printf "${C_OTHER}[${C_FAIL} ${C_OTHER}]" - fi - printf " ${C_CLEAR}$d\n" - done - ;; - *) - action=$1 - shift - # set same environment variables as init - runlevel=$(/sbin/runlevel) - ENV="PATH='/bin:/usr/bin:/sbin:/usr/sbin'" - ENV+=" PREVLEVEL='${runlevel:0:1}'" - ENV+=" RUNLEVEL='${runlevel:2:1}'" - ENV+=" CONSOLE='${CONSOLE:-/dev/console}'" - for i; do - [[ -x "/etc/rc.d/$i" ]] && cd / && eval /usr/bin/env -i $ENV "/etc/rc.d/$i" "$action" - (( ret += !! $? )) # clamp exit value to 0/1 - done -esac - -exit $ret - -# vim: set ts=2 sw=2 noet: diff --git a/rc.d b/rc.d new file mode 100755 index 0000000..02c2b6c --- /dev/null +++ b/rc.d @@ -0,0 +1,61 @@ +#!/bin/bash + +. /etc/rc.conf +. /etc/rc.d/functions + +usage() { + local name=${0##*/} + cat >&2 << EOF +usage: $name action daemon ... + +e.g: $name list + $name help + $name start sshd gpm +EOF + exit 1 +} + +(( $# < 1 )) && usage + +declare -i ret=0 +case $1 in + help) + usage + ;; + list) + cd /etc/rc.d/ + for d in *; do + have_daemon "$d" || continue + # print running / stopped satus + if ! ck_daemon "$d"; then + printf "${C_OTHER}[${C_DONE}STARTED${C_OTHER}]" + else + printf "${C_OTHER}[${C_FAIL}STOPPED${C_OTHER}]" + fi + # print auto / manual status + if ! ck_autostart "$d"; then + printf "${C_OTHER}[${C_DONE}AUTO${C_OTHER}]" + else + printf "${C_OTHER}[${C_FAIL} ${C_OTHER}]" + fi + printf " ${C_CLEAR}$d\n" + done + ;; + *) + action=$1 + shift + # set same environment variables as init + runlevel=$(/sbin/runlevel) + ENV="PATH='/bin:/usr/bin:/sbin:/usr/sbin'" + ENV+=" PREVLEVEL='${runlevel:0:1}'" + ENV+=" RUNLEVEL='${runlevel:2:1}'" + ENV+=" CONSOLE='${CONSOLE:-/dev/console}'" + for i; do + [[ -x "/etc/rc.d/$i" ]] && cd / && eval /usr/bin/env -i $ENV "/etc/rc.d/$i" "$action" + (( ret += !! $? )) # clamp exit value to 0/1 + done +esac + +exit $ret + +# vim: set ts=2 sw=2 noet: -- Sebastien "Seblu" Luttringer
With new name of script, vim doesn't reconize correctly file format. We need to set it explicitly. Signed-off-by: Sebastien Luttringer <seblu@seblu.net> --- rc.d | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/rc.d b/rc.d index 02c2b6c..49b7c2f 100755 --- a/rc.d +++ b/rc.d @@ -58,4 +58,4 @@ esac exit $ret -# vim: set ts=2 sw=2 noet: +# vim: set ts=2 sw=2 ft=sh noet: -- Sebastien "Seblu" Luttringer
We need to do this to allow a correct detection of terminal colors in functions sourced by rc.d scripts Signed-off-by: Sebastien Luttringer <seblu@seblu.net> --- rc.d | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) diff --git a/rc.d b/rc.d index 49b7c2f..2ecb342 100755 --- a/rc.d +++ b/rc.d @@ -50,6 +50,7 @@ case $1 in ENV+=" PREVLEVEL='${runlevel:0:1}'" ENV+=" RUNLEVEL='${runlevel:2:1}'" ENV+=" CONSOLE='${CONSOLE:-/dev/console}'" + ENV+=" TERM='${TERM:-linux}'" for i; do [[ -x "/etc/rc.d/$i" ]] && cd / && eval /usr/bin/env -i $ENV "/etc/rc.d/$i" "$action" (( ret += !! $? )) # clamp exit value to 0/1 -- Sebastien "Seblu" Luttringer
Signed-off-by: Sebastien Luttringer <seblu@seblu.net> --- Makefile | 3 ++- bash-completion | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletions(-) create mode 100644 bash-completion diff --git a/Makefile b/Makefile index 6923840..69f008a 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ VER := $(shell git describe) -DIRS := /etc/rc.d /etc/conf.d /etc/rc.d/functions.d /etc/cron.hourly /sbin +DIRS := /etc/rc.d /etc/conf.d /etc/rc.d/functions.d /etc/cron.hourly /sbin /etc/bash_completion.d minilogd: minilogd.o @@ -13,6 +13,7 @@ install: minilogd installdirs install -m755 -t $(DESTDIR)/etc/cron.hourly adjtime install -m755 -t $(DESTDIR)/etc/rc.d functions hwclock network netfs install -m755 -t $(DESTDIR)/sbin minilogd rc.d + install -m644 -T bash-completion $(DESTDIR)/etc/bash_completion.d/rc.d clean: rm -f minilogd minilogd.o diff --git a/bash-completion b/bash-completion new file mode 100644 index 0000000..3b0f464 --- /dev/null +++ b/bash-completion @@ -0,0 +1,18 @@ +# rc.d bash completion by Seblu <seblu@seblu.net> + +_rc.d () +{ + local action="help list start stop reload restart" + local cur="${COMP_WORDS[COMP_CWORD]}" + local caction="${COMP_WORDS[1]}" + if ((${COMP_CWORD} == 1)); then + COMPREPLY=($(compgen -W "${action}" -- "$cur")) + elif [[ "$caction" == "help" || "$caction" == "list" ]]; then + COMPREPLY=() + elif ((${COMP_CWORD} > 1)); then + COMPREPLY=($( compgen -W "$(find /etc/rc.d -maxdepth 1 -type f -executable -printf '%f\n')" -- "$cur" )) + fi +} +complete -F _rc.d rc.d + +# vim: set ts=2 sw=2 ft=sh noet: -- Sebastien "Seblu" Luttringer
just a remember about bash rc.d script. But i have a zsh one pending too. On Thu, May 5, 2011 at 3:04 AM, Sebastien Luttringer <seblu@seblu.net> wrote:
Signed-off-by: Sebastien Luttringer <seblu@seblu.net> --- Makefile | 3 ++- bash-completion | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletions(-) create mode 100644 bash-completion
diff --git a/Makefile b/Makefile index 6923840..69f008a 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ VER := $(shell git describe) -DIRS := /etc/rc.d /etc/conf.d /etc/rc.d/functions.d /etc/cron.hourly /sbin +DIRS := /etc/rc.d /etc/conf.d /etc/rc.d/functions.d /etc/cron.hourly /sbin /etc/bash_completion.d
minilogd: minilogd.o
@@ -13,6 +13,7 @@ install: minilogd installdirs install -m755 -t $(DESTDIR)/etc/cron.hourly adjtime install -m755 -t $(DESTDIR)/etc/rc.d functions hwclock network netfs install -m755 -t $(DESTDIR)/sbin minilogd rc.d + install -m644 -T bash-completion $(DESTDIR)/etc/bash_completion.d/rc.d
clean: rm -f minilogd minilogd.o diff --git a/bash-completion b/bash-completion new file mode 100644 index 0000000..3b0f464 --- /dev/null +++ b/bash-completion @@ -0,0 +1,18 @@ +# rc.d bash completion by Seblu <seblu@seblu.net> + +_rc.d () +{ + local action="help list start stop reload restart" + local cur="${COMP_WORDS[COMP_CWORD]}" + local caction="${COMP_WORDS[1]}" + if ((${COMP_CWORD} == 1)); then + COMPREPLY=($(compgen -W "${action}" -- "$cur")) + elif [[ "$caction" == "help" || "$caction" == "list" ]]; then + COMPREPLY=() + elif ((${COMP_CWORD} > 1)); then + COMPREPLY=($( compgen -W "$(find /etc/rc.d -maxdepth 1 -type f -executable -printf '%f\n')" -- "$cur" )) + fi +} +complete -F _rc.d rc.d + +# vim: set ts=2 sw=2 ft=sh noet: -- Sebastien "Seblu" Luttringer
-- Sébastien Luttringer www.seblu.net
Hi Sébastien, Is your branch on github ready to be reviewed now? I think you implemented some suggestions I made, but I don't know if you finished. Did you have a look at the other bash completion patch on the list to see if it adds anything not already in this patch? -t On Wed, May 18, 2011 at 9:03 PM, Seblu <seblu@seblu.net> wrote:
just a remember about bash rc.d script. But i have a zsh one pending too.
On Thu, May 5, 2011 at 3:04 AM, Sebastien Luttringer <seblu@seblu.net> wrote:
Signed-off-by: Sebastien Luttringer <seblu@seblu.net> --- Makefile | 3 ++- bash-completion | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletions(-) create mode 100644 bash-completion
diff --git a/Makefile b/Makefile index 6923840..69f008a 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ VER := $(shell git describe) -DIRS := /etc/rc.d /etc/conf.d /etc/rc.d/functions.d /etc/cron.hourly /sbin +DIRS := /etc/rc.d /etc/conf.d /etc/rc.d/functions.d /etc/cron.hourly /sbin /etc/bash_completion.d
minilogd: minilogd.o
@@ -13,6 +13,7 @@ install: minilogd installdirs install -m755 -t $(DESTDIR)/etc/cron.hourly adjtime install -m755 -t $(DESTDIR)/etc/rc.d functions hwclock network netfs install -m755 -t $(DESTDIR)/sbin minilogd rc.d + install -m644 -T bash-completion $(DESTDIR)/etc/bash_completion.d/rc.d
clean: rm -f minilogd minilogd.o diff --git a/bash-completion b/bash-completion new file mode 100644 index 0000000..3b0f464 --- /dev/null +++ b/bash-completion @@ -0,0 +1,18 @@ +# rc.d bash completion by Seblu <seblu@seblu.net> + +_rc.d () +{ + local action="help list start stop reload restart" + local cur="${COMP_WORDS[COMP_CWORD]}" + local caction="${COMP_WORDS[1]}" + if ((${COMP_CWORD} == 1)); then + COMPREPLY=($(compgen -W "${action}" -- "$cur")) + elif [[ "$caction" == "help" || "$caction" == "list" ]]; then + COMPREPLY=() + elif ((${COMP_CWORD} > 1)); then + COMPREPLY=($( compgen -W "$(find /etc/rc.d -maxdepth 1 -type f -executable -printf '%f\n')" -- "$cur" )) + fi +} +complete -F _rc.d rc.d + +# vim: set ts=2 sw=2 ft=sh noet: -- Sebastien "Seblu" Luttringer
-- Sébastien Luttringer www.seblu.net
On Wed, May 18, 2011 at 9:08 PM, Tom Gundersen <teg@jklm.no> wrote:
Hi Sébastien,
Is your branch on github ready to be reviewed now? I think you implemented some suggestions I made, but I don't know if you finished. As you ask me, i sent patch on project to review and let you pull when you think it's good. Ok i will sent you mail about pull request.
Did you have a look at the other bash completion patch on the list to see if it adds anything not already in this patch?
Not yet. I just works be done twice. I will look if something is better implemented and a zsh completion is in AUR. i will send you more tonight. -- Sébastien Luttringer www.seblu.net
participants (3)
-
Sebastien Luttringer
-
Seblu
-
Tom Gundersen