[Lunar-commits] r23659 - in lunar/trunk: sbin var/lib/lunar/menu

Auke Kok sofar at lunar-linux.org
Fri Mar 16 07:31:23 CET 2007


Author: sofar
Date: 2007-03-16 07:31:23 +0100 (Fri, 16 Mar 2007)
New Revision: 23659

Added:
   lunar/trunk/var/lib/lunar/menu/alias.menu
Modified:
   lunar/trunk/sbin/lunar
Log:
Provide a simple menu to select, set and unset aliases


Modified: lunar/trunk/sbin/lunar
===================================================================
--- lunar/trunk/sbin/lunar	2007-03-16 05:25:04 UTC (rev 23658)
+++ lunar/trunk/sbin/lunar	2007-03-16 06:31:23 UTC (rev 23659)
@@ -431,7 +431,8 @@
     N_HELP="Check all modules but do not fix the internal state"
     D_HELP="Check and fix the dependency database of lunar"
     P_HELP="Prune old sources and install/compile logs"
-    
+    A_HELP="Change selected or select new alias mappings"
+
     COMMAND=`$DIALOG  --title "Maintenance Menu"                         \
                       --ok-label      "Select"                           \
                       --cancel-label  "Exit"                             \
@@ -443,16 +444,20 @@
                       "F"     "Fix everything"                 "$F_HELP" \
                       "N"     "Check everything but don't fix" "$N_HELP" \
                       "D"     "Fix dependencies"               "$D_HELP" \
-		      "P"     "Prune old sources and logs"     "$P_HELP"`
+                      "P"     "Prune old sources and logs"     "$P_HELP" \
+                      "A"     "Select or Change Aliases"       "$A_HELP"`
   do
     case $COMMAND in
      F)  lunar fix          ;;
      N)  lunar nofix        ;;
      D)  lunar fixdepends   ;;
      P)  lunar prune        ;;
+     A)  select_aliases     ;;
     esac
-    message "${MESSAGE_COLOR}Press enter to return...${DEFAULT_COLOR}"
-    read
+    if [ $COMMAND != "A" ] ; then
+      message "${MESSAGE_COLOR}Press enter to return...${DEFAULT_COLOR}"
+      read
+    fi
   done
 }
 

Added: lunar/trunk/var/lib/lunar/menu/alias.menu
===================================================================
--- lunar/trunk/var/lib/lunar/menu/alias.menu	                        (rev 0)
+++ lunar/trunk/var/lib/lunar/menu/alias.menu	2007-03-16 06:31:23 UTC (rev 23659)
@@ -0,0 +1,85 @@
+############################################################
+#                                                          #
+# This code is written for Lunar Linux, see                #
+# http://lunar-linux.org                                   #
+#                                                          #
+############################################################
+#                                                          #
+# Copyright 2007 (c) GPLv2 - Auke Kok                      #
+#                                                          #
+############################################################
+
+
+alias_menu_list_aliases()
+{
+	for A in `cut -d: -f1 $MOONBASE/aliases`; do
+		echo ${A:1}
+		CHOICE=$(get_local_config `echo LUNAR_ALIAS_${A:1}`)
+		if [ -n "$CHOICE" ] ; then
+			echo "$CHOICE"
+		else
+			echo "[unset]"
+		fi
+	done
+}
+
+
+alias_menu_list_alias_choices()
+{
+	echo "None"
+	echo "None"
+	if [ -z "$(get_local_config `echo LUNAR_ALIAS_$1`)" ] ; then
+		echo "on"
+	else
+		echo "off"
+	fi
+	IFS=$STANDARD_IFS
+	for C in `grep "^%$1:" $MOONBASE/aliases | cut -d: -f2`; do
+		echo "$C"
+		echo "$C"
+		if [ $(get_local_config `echo LUNAR_ALIAS_$1`) == "$C" ] ; then
+			echo "on"
+		else
+			echo "off"
+		fi
+	done
+}
+
+
+select_aliases()
+{
+	export IFS=$ENTER_IFS
+
+	while true ; do
+		DEFAULT=${CHOICE}
+		CHOICE=`$DIALOG --title "Select Lunar Aliases" \
+		                --ok-label "Select" \
+		                --cancel-label "Close" \
+		                --default-item "$DEFAULT" \
+		                --menu "" 0 0 0 \
+		                $(alias_menu_list_aliases)`
+		if [ $? != 0 ]; then
+			return
+		fi
+
+		# modify an alias
+		DEFAULT=$(get_local_config `echo LUNAR_ALIAS_$CHOICE`)
+		if [ -z "$DEFAULT" ] ; then
+			DEFAULT="None"
+		fi
+		ACHOICE=`$DIALOG --title "Select Lunar Aliases" \
+		                 --ok-label "Select" \
+		                 --cancel-label "Close" \
+		                 --default-item "$DEFAULT" \
+		                 --radiolist "" 0 0 0 \
+		                 $(alias_menu_list_alias_choices $CHOICE)`
+		if [ $? == 0 ]; then
+			# modify it
+			if [ "$ACHOICE" != "None" ] ; then
+				set_local_config `echo LUNAR_ALIAS_$CHOICE` "$ACHOICE"
+			else
+				unset_local_config `echo LUNAR_ALIAS_$CHOICE`
+			fi
+		fi
+	done
+}



More information about the Lunar-commits mailing list