From 7aa1654039fea9894ff38ca977f05c2e7d47618e Mon Sep 17 00:00:00 2001 From: "Casper Ti. Vector" Date: Fri, 9 Nov 2012 20:38:00 +0800 Subject: [PATCH] Minor improvements to coding style. --- src/cdm | 32 +++++++++++++++----------------- src/cdm-xlaunch | 6 +++--- src/cdmrc | 12 ++++++------ src/profile.sh | 2 +- 4 files changed, 25 insertions(+), 27 deletions(-) diff --git a/src/cdm b/src/cdm index 080d050..239ca4b 100755 --- a/src/cdm +++ b/src/cdm @@ -48,7 +48,7 @@ yesno() case "$value" in [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1) return 0;; [Nn][Oo]|[Ff][Aa][Ll][Ss][Ee]|[Oo][Ff][Ff]|0) return 1;; - *) warn "Invalid value for \`$1'; falling back to \`no' for now.";; + *) warn "invalid value for \`$1'; falling back to \`no' for now.";; esac } @@ -83,7 +83,7 @@ cktimeout=${cktimeout:-30} serverargs=${serverargs:-'-nolisten tcp'} # Offer all available sessions in /etc/X11/Sessions, -# if binlist if not explicitly set in cdmrc. +# if $binlist if not explicitly set in cdmrc. if [[ "${#binlist[@]}" == 0 ]]; then binlist=($(find /etc/X11/Sessions -maxdepth 1 -type f)) @@ -121,13 +121,14 @@ case ${flaglist[$binindex]} in # *C*onsole programs. [Cc]) clear + # If $bin is a login shell, it might `exec' cdm again, causing an endless # loop. To solve this problem, export $CDM_SPAWN when `exec'ing $bin and # only let the shell automatically `exec' cdm when $CDM_SPAWN is not set. # See also the example shell profile file shipped with the cdm package. # Also untrap SIGINT and SIGTSTP before spawning process: If this is not - # done, *ANY* child process of *ANY* child (bash) shell will completely + # done, any child process of any child (bash) shell will completely # ignore SIGINT, which is rather confusing, and cannot be undone. trap - SIGINT SIGTSTP @@ -138,12 +139,10 @@ case ${flaglist[$binindex]} in [Xx]) clear - # If X is already running and locktty=yes, activate it - if $(yesno locktty); then - if xdpyinfo -display ":$display.0" &> /dev/null; then - chvt "$((display+xtty))" - exitnormal - fi + # If X is already running and locktty=yes, activate it. + if $(yesno locktty) && xdpyinfo -display ":$display.0" &> /dev/null; then + chvt "$((display+xtty))" + exitnormal fi # Get the first empty display. @@ -161,17 +160,16 @@ case ${flaglist[$binindex]} in fi done - # run X in current tty - if [[ $xtty == "keep" ]]; then - vt=$(tty) - vt=${vt#/dev/} - if [[ $vt != tty* ]]; then - error "error: invalid TTY" + # Support for running X in current tty. + if [[ $xtty == 'keep' ]]; then + vt="$(tty)" + if [[ "$vt" != '/dev/tty'* ]]; then + error 'invalid TTY.' exiterror fi - vt=${vt#tty} + vt="${vt#/dev/tty}" else - vt=$((xtty+display)) + vt="$((xtty+display))" fi serverargs=":${display} $serverargs vt$vt" diff --git a/src/cdm-xlaunch b/src/cdm-xlaunch index ea92e5a..5535ec7 100755 --- a/src/cdm-xlaunch +++ b/src/cdm-xlaunch @@ -56,7 +56,7 @@ done # Do first to avoid race conditions. if $consolekit; then - info "waiting for ConsoleKit to register X session." + info 'waiting for ConsoleKit to register X session.' sleep "$cktimeout" & clockpid=$! dbuspidfifo=$(mktemp --dry-run --tmpdir $name.XXXXXXXX) if ! mkfifo "$dbuspidfifo"; then @@ -86,11 +86,11 @@ if $consolekit; then if wait "$clockpid" >& /dev/null then kill "$dbuspid" - error "ConsoleKit registration timed out." + error 'ConsoleKit registration timed out.' exit 1 else kill "$dbuspid" - info "ConsoleKit registration succeeded." + info 'ConsoleKit registration succeeded.' exit 0 fi fi diff --git a/src/cdmrc b/src/cdmrc index 1d0525c..daf4449 100644 --- a/src/cdmrc +++ b/src/cdmrc @@ -8,17 +8,17 @@ # # (An example:) # binlist=( -# "~/.xsession" # Launch your X session, -# "/bin/bash --login" # or just execute your shell, -# "/usr/bin/fbterm" # or start a frame buffer console, -# "/usr/bin/cdm ~/.submenu.cdmrc" # or go to a submenu :) +# '~/.xsession' # Launch your X session, +# '/bin/bash --login' # or just execute your shell, +# '/usr/bin/fbterm' # or start a frame buffer console, +# '/usr/bin/cdm ~/.submenu.cdmrc' # or go to a submenu :) # ) # List all program display names, one-by-one matched with $binlist. # Names with whitespaces should be quoted or escaped. # # (Continued example:) -# namelist=("X session" Console FBTerm "Sub menu") +# namelist=('X session' Console FBTerm 'Sub menu') # Type of the programs, one-by-one matched with $binlist. # `C' for *C*onsole programs, which would be `exec'ed. @@ -39,7 +39,7 @@ countfrom=0 display=0 # Where should the first X tty be spawned? -# special value 'keep' causes to run X in current tty +# special value `keep' causes to run X in current tty. xtty=7 # Should cdm(1) stick to the specified display? diff --git a/src/profile.sh b/src/profile.sh index c5eae0a..dd7716a 100644 --- a/src/profile.sh +++ b/src/profile.sh @@ -1,4 +1,4 @@ -if [[ "$(tty)" == /dev/tty* ]]; then +if [[ "$(tty)" == '/dev/tty'* ]]; then [[ -n "$CDM_SPAWN" ]] && return [[ -z "$DISPLAY$SSH_TTY" ]] && exec cdm fi