From 536010fea5d15bc3b6870618ab55da19151a9163 Mon Sep 17 00:00:00 2001 From: polyphemus Date: Sun, 31 Mar 2013 11:56:26 +0200 Subject: [PATCH 1/3] Cleanup of $binlist behaviour. Show error when no programs are found. Don't use $countdown if only one program is available. Don't call clear when only one program is available/dialog is not called. --- src/cdm | 51 +++++++++++++++++++++++++-------------------------- 1 file changed, 25 insertions(+), 26 deletions(-) diff --git a/src/cdm b/src/cdm index 6ea589f..3e4adc6 100755 --- a/src/cdm +++ b/src/cdm @@ -118,37 +118,38 @@ if [[ "${#binlist[@]}" == 0 ]]; then done fi -# Generate the main menu. -menu=() -for ((count = 0; count < ${#namelist[@]}; count++)); do - menu=("${menu[@]}" "$((count+countfrom))" "${namelist[${count}]}") -done - -# Override dialog display if only one option is available. -if [[ "$count" == 1 ]]; then - binindex=0 -else - # Display selection dialog. - binindex=$( - DIALOGRC="$dialogrc" dialog --colors --stdout \ - --backtitle "$longname v$ver" \ - --ok-label ' Select ' --cancel-label ' Exit ' \ - --menu 'Select session' 0 0 0 "${menu[@]}" - ) - if [[ $? != 0 ]]; then +case "${#binlist[@]}" in + 0) + error "No programs found in cdm config file, /etc/X11/Sessions or /usr/share/xsessions." + exiterror + ;; + 1) + # No need to call dialog AND clear, only one possible program + binindex=0 + ;; + *) + menu=() + for ((count = 0; count < ${#namelist[@]}; count++)); do + menu=("${menu[@]}" "$((count+countfrom))" "${namelist[${count}]}") + done + binindex=$( + DIALOGRC="$dialogrc" dialog --colors --stdout \ + --backtitle "$longname v$ver" --ok-label ' Select ' \ + --cancel-label ' Exit ' --menu 'Select session' 0 0 0 "${menu[@]}" + ) + if [[ $? != 0 ]]; then + clear; exitnormal + fi clear - exitnormal - fi -fi + let binindex-=countfrom + ;; +esac # Run $bin according to its flag. -let binindex-=countfrom bin=($(eval echo "${binlist[${binindex}]}")) 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. @@ -164,8 +165,6 @@ case ${flaglist[$binindex]} in # *X* programs. [Xx]) - clear - # If X is already running and locktty=yes, activate it. if $(yesno locktty) && xdpyinfo -display ":$display.0" &> /dev/null; then chvt "$((display+xtty))" From 3412c9dc7c68642ef712872434b4b99945357a1f Mon Sep 17 00:00:00 2001 From: polyphemus Date: Sun, 31 Mar 2013 09:21:14 +0200 Subject: [PATCH 2/3] Check if directories exist before try to \'find\' files in them. --- src/cdm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cdm b/src/cdm index 3e4adc6..fc95b89 100755 --- a/src/cdm +++ b/src/cdm @@ -85,7 +85,7 @@ cktimeout=${cktimeout:-30} # Offer all available sessions in /etc/X11/Sessions, # if $binlist if not explicitly set in cdmrc. -if [[ "${#binlist[@]}" == 0 ]]; then +if [[ "${#binlist[@]}" == 0 && -d /etc/X11/Sessions ]]; then binlist=($(find /etc/X11/Sessions -maxdepth 1 -type f)) flaglist=($(sed 's/[[:digit:]]\+/X/g' <<< ${!binlist[@]})) namelist=(${binlist[@]##*/}) @@ -94,7 +94,7 @@ fi # If $binlist is not set in cdmrc or by files in /etc/X11/Sessions, # try .desktop files in /usr/share/xsessions/ . -if [[ "${#binlist[@]}" == 0 ]]; then +if [[ "${#binlist[@]}" == 0 && -d /usr/share/xsessions ]]; then desktopsessions=($(find /usr/share/xsessions/ -regex .\*.desktop)) #TODO: allow full quoting and expansion according to desktop entry spec: # http://standards.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html#exec-variables From f8ff090e92653bc8a2c60133934b2525e2a7fcdc Mon Sep 17 00:00:00 2001 From: polyphemus Date: Wed, 3 Apr 2013 11:42:51 +0200 Subject: [PATCH 3/3] Add '/usr/share/xsessions' to comments as possible sessions location. --- src/cdmrc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/cdmrc b/src/cdmrc index 07ef72f..668da95 100644 --- a/src/cdmrc +++ b/src/cdmrc @@ -4,7 +4,8 @@ # Values set here is the default as in cdm(1). # List of programs, commands with whitespaces should be quoted or escaped. -# If unset, all sessions in /etc/X11/Sessions are offered as choices. +# If unset, all sessions in /etc/X11/Sessions or /usr/share/xsessions are +# offered as choices. # # (An example:) # binlist=(