#!/bin/bash # # Script to add an "npp" function to invoke Notepad++ to a bash shell session. # # $Id: zzzz_91.npp.sh 446 2020-12-21 14:05:26Z samedge $ # # Uses bash-specific extensions. [ "x${BASH_VERSION}" = "x" ] && return 0 function npp { [[ -z "${SSH_CLIENT-}" ]] || { echo 'Appear to be running via secure shell - cannot launch Windows GUI executables.' 1>&2 ; return 255 ; } if [[ -n "${DISPLAY-}" ]] ; then local -r display_host="${DISPLAY%:*}" if [[ -n "$display_host" && "$display_host" != "localhost" && "$display_host" != "127.0.0.1" ]] ; then { echo 'Appear to be running from a remote X client - cannot launch Windows GUI executables.' 1>&2 ; return 255 ; } fi fi local exe= if test -v _NOTEPAD_PLUS_PLUS_EXE && [ -x "$_NOTEPAD_PLUS_PLUS_EXE" ] ; then exe="$_NOTEPAD_PLUS_PLUS_EXE" else local -a path=() test -v PROGRAMFILES && path+=("$PROGRAMFILES") test -v ProgramW6432 && path+=("$ProgramW6432") path+=("$(cygpath --windows -F 42)") # :NOTE: Work-around for parsing "ProgramFiles(x86)" as a variable name - bash chokes! path+=('C:\Program Files') path+=('C:\Program Files (x86)') local dir for dir in "${path[@]}" do if [[ -n "$dir" ]] ; then local candidate candidate="$(cygpath --unix --absolute -- "$dir")/Notepad++/notepad++" #candidate="$dir\\Notepad++\\notepad++.exe" if [ -x "$candidate" ] ; then exe="$candidate" break fi fi done [[ -n "$exe" ]] || { echo 'Cannot find Notepad++ Windows executable.' 1>&2 ; return 255 ; } export _NOTEPAD_PLUS_PLUS_EXE="$exe" fi local -i dry_run=0 local -i next_is_not_filename=0 local -i next_is_optarg=0 local wait= local -a argv=() local arg for arg in "$@" do if [[ "${arg:0:1}" == '-' ]] && (( ! next_is_optarg )) ; then case "$arg" in --dry-run ) arg= dry_run=1 next_is_not_filename=0 next_is_optarg=0 ;; --wait ) wait="--wait" arg="-multiInst" next_is_not_filename=0 next_is_optarg=0 ;; --help | -multiInst | -noPlugin | -nosession | -notabbar | -ro | -systemtray | -loadingTime | -alwaysOnTop | -openSession | -r | -quickPrint ) next_is_not_filename=0 next_is_optarg=0 ;; -l* | -L* | -n* | -c* | -p* | -x* | -y* | -qn* | -qt* | -qSpeed* ) next_is_not_filename=0 next_is_optarg=0 ;; -qf* ) next_is_not_filename=0 next_is_optarg=0 arg="-qf$(cygpath --windows --absolute -- "$(realpath "${arg:3}")")" || return $? ;; * ) next_is_not_filename=0 next_is_optarg=0 ;; esac else if (( ! next_is_not_filename )) ; then arg="$(cygpath --windows --absolute -- "$(realpath "$arg")")" || return $? fi next_is_not_filename=0 next_is_optarg=0 fi [ -n "$arg" ] && argv+=("\"$arg\"") done local -r -i argc="${#argv[@]}" (( dry_run )) || if (( argc != 0 )) ; then cygstart $wait "$exe" "${argv[@]}" else cygstart $wait "$exe" fi }