Open Total Commander from Cygwin

Discuss and announce Total Commander plugins, addons and other useful tools here, both their usage and their development.

Moderators: Hacker, petermad, Stefan2, white

Post Reply
User avatar
robertmarkbram
Junior Member
Junior Member
Posts: 10
Joined: 2009-07-31, 02:15 UTC

Open Total Commander from Cygwin

Post by *robertmarkbram »

Hi All,

I use Cygwin command line a lot. Frequently I summon my file explorer (Explorer, Midnight Commander, Directory Opus and now Total Commander) from the command line, so here is my script to do that for Total Commander: http://robertmarkbramprogrammer.blogspot.com/2009/08/open-total-commander-from-cygwin.html

I wrote it to give me an easy way to:

- Open paths in currently running instance.
- Open paths in existing or new tabs.
- Specify paths for left and/or right panels.


Code for it..

Code: Select all

#!/bin/bash
#===============================================================================
#
#          FILE:  totalCommander.sh
#
#         USAGE:  see usage
#
#   DESCRIPTION:  Open Total Commander to whatever path.
#
#       OPTIONS:  - see usage
#  REQUIREMENTS:  - Total Commander be installed http://www.ghisler.com/
#                 - Paths requested to be opened exist
#          BUGS:  ---
#         NOTES:  ---
#        AUTHOR:  Robert Mark Bram (RMB), robertmarkbram@gmail.com
#       COMPANY:  http://robertmarkbramprogrammer.blogspot.com/
#       VERSION:  1.0
#       CREATED:  07/31/09 16:54:46 AUSEST
#      REVISION:  ---
#===============================================================================

set -o nounset                              # Treat unset variables as an error


#-------------------------------------------------------------------------------
#  Variables for this script.
#-------------------------------------------------------------------------------
# Open new tabs? Blank for no, '/T' for yes.
newTab=
# Path to open on left.
tcpathLeft=
# Path to open on right.
tcpathRight=
# Total Commander command.
totalCommander=/apps/totalcmd/TOTALCMD.EXE
# Should we be verbose?
verbose=no


#-------------------------------------------------------------------------------
#  Common functions for this script.
#-------------------------------------------------------------------------------


#===  FUNCTION  ================================================================
#          NAME:  checkVars
#   DESCRIPTION:  Check initial state of vars in this script.
#    PARAMETERS:
#       RETURNS:
#===============================================================================
function checkVars() {
   if [ -z "$tcpathLeft" -a -z "$tcpathRight" ] ; then
      tcpathLeft=.
   elif [ ! -z "$tcpathLeft" -a ! -e "${tcpathLeft}" ] ; then
      usage "Left location [${tcpathLeft}] does not exist."
      exit 2;
   elif [ ! -z "$tcpathRight" -a ! -e "${tcpathRight}" ] ; then
      usage "Right location [${tcpathRight}] does not exist."
      exit 2;
   fi
   type $totalCommander &> /dev/null
   if [ ! -e "$totalCommander" ]; then
      echo "There is no spoon. Or total commander @ '$totalCommander'."
      exit 2;
   fi
}


#===  FUNCTION  ================================================================
#          NAME:  message
#   DESCRIPTION:  Output message if verbose is on
#    PARAMETERS:  message to be printed
#       RETURNS:  -
#===============================================================================
message ()
{
   if [ "$verbose" == "yes" ] ; then
      echo -e "${1}"
   fi
}    # ----------  end of function message  ----------


#===  FUNCTION  ================================================================
#          NAME:  processArgs
#   DESCRIPTION:  Check command line arguments.
#    PARAMETERS:  $@ from this script invocation
#       RETURNS:  Exit or take other action with error messages
#===============================================================================
processArgs ()
{
   # Process all the opening arguments.
   while [ "$#" -gt 0 ]
   do # until we have no more args to process.
      case "${1}" in
         "-h"     )  usage; exit 0;;
         "--help" )  usage; exit 0;;
         "-l"     )  tcpathLeft="${2}"; shift; shift;;
         "-r"     )  tcpathRight="${2}"; shift; shift;;
         "-t"     )  newTab="/T"; shift;;
         "-v"     )  verbose=yes; shift;;
         *        )  usage "Unknown option: $1" ; exit 2;;
      esac
   done
}    # ----------  end of function processArgs  ----------


#===  FUNCTION  ================================================================
#          NAME:  help
#   DESCRIPTION:  Output usage statement and exit.
#    PARAMETERS:  Error message.
#       RETURNS:
#===============================================================================
function usage() {
# Here document for help.. less or cat
errMessage=
if [ "$#" -gt 0 ] ; then
   errMessage=$1
else
   errMessage=HELP
fi
# Here document for help.. less or cat
cat << STOP_HELP
$errMessage
usage: $0 [-t] [-l leftPath] [-r rightPath]
Open Total Commander to paths, if specified, or current directory otherwise.
Always uses currently running instance. Opens new instance if none are running.
   -l    - Path to open in left tab.
            If neither -l or -r are given, default value is "-l .".
   -r    - Path to open in right tab.
            If neither -l or -r are given, default value is "-l .".
   -t    - Open paths in new tabs.
   -v    - verbose
Examples
1) Open current directory in left panel, current tab.
      $0
2) Open current directory in left panel, parent directory in right panel in new
   tabs.
      $0 -l . -r .. -t
STOP_HELP
}


#-------------------------------------------------------------------------------
#  Script Logic
#-------------------------------------------------------------------------------


processArgs "$@"
checkVars

if [ ! -z "$tcpathLeft" ] ; then
   tcpathLeft=/L=`cygpath -d -a "${tcpathLeft}"`
fi
if [ ! -z "$tcpathRight" ] ; then
   tcpathRight=/R=`cygpath -d -a "${tcpathRight}"`
fi

message "TC with left [$tcpathLeft], right [$tcpathRight] with new tab [$newTab]."

$totalCommander /O $newTab "${tcpathLeft}" "${tcpathRight}" &

# echo Done.


[/code]
User avatar
petermad
Power Member
Power Member
Posts: 16032
Joined: 2003-02-05, 20:24 UTC
Location: Denmark
Contact:

Post by *petermad »

Maybe this topic should rather have been posted in the "Plugins and addons: devel.+support (English)" section ??
License #524 (1994)
Danish Total Commander Translator
TC 11.51 32+64bit on Win XP 32bit & Win 7, 8.1 & 10 (22H2) 64bit, 'Everything' 1.5.0.1391a
TC 3.60b4 on Android 6, 13, 14
TC Extended Menus | TC Languagebar | TC Dark Help | PHSM-Calendar
User avatar
Clo
Moderator
Moderator
Posts: 5731
Joined: 2003-12-02, 19:01 UTC
Location: Bordeaux, France
Contact:

Right place

Post by *Clo »

[mod]Thread moved to “Plugins and Addons…”
Clo, moderator.[/mod]
#31505 Traducteur Français de TC French translator Aide en Français Tutoriels Français English Tutorials
Post Reply