From: "Vadim (vadcx)" <[email protected]>

The icon is supposed to be adaptive based on the terminal used,
otherwise fallback to Cygwin's default icon found in the installation folder

If an icon file is not found, nothing will happen (either blank icon or missing 
icon).
---
 src/chere | 70 ++++++++++++++++++++++++++++++++-----------------------
 1 file changed, 41 insertions(+), 29 deletions(-)

diff --git a/src/chere b/src/chere
index 4d9730b..9c6b77e 100755
--- a/src/chere
+++ b/src/chere
@@ -352,11 +352,14 @@ setup_for_term()
  # command
  TERM_ARGS=""
  RUN_ARGS=""
+ ICON_PATH_WIN="$(cygpath -w "/Cygwin-Terminal.ico")" # optionally takes 
",iconID"
+ local term_has_icon
  case $1 in
   cmd )
        case $VER in
        CYGWIN_NT* )
-        TERM_EXE=cmd.exe;;
+        TERM_EXE=cmd.exe
+        term_has_icon=1;;
        * )
         TERM_EXE=command.com;;
        esac
@@ -370,20 +373,26 @@ setup_for_term()
   mintty )
        TERM_EXE="/bin/mintty.exe"
        TERM_ARGS="$USER_TERM_OPTIONS"
-       RUN_EXE="";; # For some reason run.exe breaks mintty
+       RUN_EXE="" # For some reason run.exe breaks mintty
+       term_has_icon=1;;
   xterm )
        TERM_EXE="/bin/xterm.exe"
        TERM_ARGS="-display $DISP $USER_TERM_OPTIONS"
-       RUN_ARGS="-p /usr/X11R6/bin";;
+       RUN_ARGS="-p /usr/X11R6/bin"
+       term_has_icon=1;;
   * )
-       echo $0 Error: Unknown terminal $this_term
+       echo "$0 Error: Unknown terminal '$this_term'"
        echo
        echo Supported terminals:
-       echo $KNOWN_TERMS
+       echo "$KNOWN_TERMS"
        echo
        echo Use -h for help
        exit;;
  esac
+
+ if [ "$term_has_icon" == "1" ]; then
+  ICON_PATH_WIN="$(cygpath -w "$(command -v "$TERM_EXE")")"
+ fi
 }
 
 # Setup to install a particular shell.
@@ -749,22 +758,24 @@ list_cygwin_registry_keys()
 #  $2 - Shell being installed
 #  $3 - Accelerator
 #  $4 - Command
+#  $5 - Windows Icon Path
 # Uses:
 #  FORCE
 install_context_menu()
 {
- if [ $FORCE = t ] || ! $REGTOOL_ check $1 2> /dev/null ; then
+ if [ "$FORCE" = t ] || ! $REGTOOL_ check "$1" 2> /dev/null ; then
   # Make sure the registry key exists
   create_registry_key "$1"
 
-  $REGTOOL -s set $1/ \"$3\"
-  $REGTOOL add $1/command
-  $REGTOOL -e set $1/command/ \"$4\"
+  $REGTOOL -s set "$1/" "\"$3\""
+  $REGTOOL -s set "$1/Icon" "\"$5\""
+  $REGTOOL add "$1/command"
+  $REGTOOL -e set "$1/command/" "\"$4\""
  else
-  echo $0 Warning: Not overriding existing entry
+  echo "$0 Warning: Not overriding existing entry"
   echo
-  echo Entry for $2 already exists in the Registry Drive Key
-  echo Use -f to override existing key.
+  echo "Entry for '$2' already exists in the Registry Drive Key"
+  echo "Use -f to override existing key."
   echo
  fi
 }
@@ -817,47 +828,48 @@ create_uninstall_item()
 install()
 {
  local TERM_EXE SHELL_EXE SHELL_CMD SHELL_BG_CMD START_CMD ACCEL CPH_DESC 
UINST_ARG
- setup_for_term  $1
- setup_for_shell $2
+ local ICON_PATH_WIN
+ setup_for_term  "$1"
+ setup_for_shell "$2"
 
  # Check TERM and SHELL are present
  if [ ! -x "$TERM_EXE" ] && [ "$1" != cmd ]; then
   if [ $FORCE = t ]; then
-   echo $0 Warning: $TERM_EXE not found
+   echo "$0 Warning: TERM_EXE='$TERM_EXE' not found or not executable"
   else
-   echo $0 Error: $TERM_EXE not found
+   echo "$0 Error: TERM_EXE='$TERM_EXE' not found or not executable"
    echo
-   echo $TERM_EXE is where I expect to find your $1
-   echo Use -f to install anyway.
+   echo "'$TERM_EXE' is where I expect to find your '$1'"
+   echo "Use -f to install anyway."
    exit
   fi
  fi
  if [ ! -x "$SHELL_EXE" ] && [ "$2" != cmd ]; then
   if [ $FORCE = t ]; then
-   echo $0 Warning: $SHELL_EXE not found
+   echo "$0 Warning: SHELL_EXE='$SHELL_EXE' not found or not executable"
   else
-   echo $0 Error: $SHELL_EXE not found
+   echo "$0 Error: SHELL_EXE='$SHELL_EXE' not found or not executable"
    echo
-   echo $SHELL_EXE is where I expect to find $2
-   echo Use -f to install anyway.
+   echo "$SHELL_EXE is where I expect to find '$2'"
+   echo "Use -f to install anyway."
    exit
   fi
  fi
 
- build_start_cmd $1 $2 $METHOD
+ build_start_cmd "$1" "$2" "$METHOD"
 
  ####### Install ###########
- install_context_menu $DRIVE_KEY/$PFX$2 $2 "$ACCEL" "$START_CMD $SHELL_CMD"
- install_context_menu $DIR_KEY/$PFX$2 $2 "$ACCEL" "$START_CMD $SHELL_CMD"
+ install_context_menu "$DRIVE_KEY/$PFX$2" "$2" "$ACCEL" "$START_CMD 
$SHELL_CMD" "$ICON_PATH_WIN"
+ install_context_menu "$DIR_KEY/$PFX$2" "$2" "$ACCEL" "$START_CMD $SHELL_CMD" 
"$ICON_PATH_WIN"
 
  # Background keys only work on Windows 7. Don't install on XP.
- if [ $VER != "CYGWIN_NT-5.1" ] ; then
-   install_context_menu $DRIVE_BG_KEY/$PFX$2 $2 "$ACCEL" "$START_CMD 
$SHELL_BG_CMD"
-   install_context_menu $DIR_BG_KEY/$PFX$2 $2 "$ACCEL" "$START_CMD 
$SHELL_BG_CMD"
+ if [ "$VER" != "CYGWIN_NT-5.1" ] ; then
+   install_context_menu "$DRIVE_BG_KEY/$PFX$2" "$2" "$ACCEL" "$START_CMD 
$SHELL_BG_CMD" "$ICON_PATH_WIN"
+   install_context_menu "$DIR_BG_KEY/$PFX$2" "$2" "$ACCEL" "$START_CMD 
$SHELL_BG_CMD" "$ICON_PATH_WIN"
  fi
 
  if [ $DO_WIN_UINST = t ]; then
-  create_uninstall_item $UINST_KEY/$PFX$2 $2
+  create_uninstall_item "$UINST_KEY/$PFX$2" "$2"
  fi
 }
 
-- 
2.50.1

Reply via email to