exe in path directory, "command not found"

Sam Edge sam.edge@gmx.com
Wed Mar 15 07:27:16 GMT 2023


On 15/03/2023 03:00, WyntrHeart via Cygwin wrote:
> I've added /cygdrive/c/program\ files/notepad++ to my path in .bash_profile,
> double checking with echo to make sure that the directory is in the path. But
> when I type "notepad++.exe" or "notepad++" I get "bash: notepad++: command
> not found". I did restart the terminal before testing to make sure that
> .bash_profile was loaded and path was updated. Is there something I'm doing
> wrong here or is this a bug?
>

As per René & Eliot but anyone who uses Notepad++ a lot from Cygwin might be
interested in the attached script which can be put in /etc/profile.d/ or
sourced from your .bashrc. It creates a shell function 'npp' that parses the
command line and translates pathnames to Windows format before passing to
Notepad++. It adds a --wait argument to cause the caller to wait on Notepad++
instance exiting before returning.

The second script ('npp') provides a wrapper around the first for POSIX programs
looking for an executable e.g. git commit message editor etc.

I've done the same for kdiff3 if anyone wants them.

--
Sam Edge

-------------- next part --------------
#!/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
}
-------------- next part --------------
#!/bin/bash
#
# Generic wrapper for bash functions so they can be invoked by external tools.
# If the wrapper filename (or symlink) ends in 'w' then this is stripped and
# the function is invoked with the --wait option before any command line ones.
#
# The function definition must be in a file in /etc/profile.d/ of the form
# *.CMD.sh when CMD is the symlink filename without any trailing 'w' character.
#
# $Id: npp 222 2020-03-24 15:13:00Z SamEdge $
#

set -u
set -e
set -o pipefail

wait=
declare cmdname="$0"
cmdname="${cmdname##*/}"
if [[ "${cmdname: -1}" == 'w' ]] ; then
    cmdname="${cmdname::-1}"
    wait="--wait"
fi

. /etc/profile.d/*."$cmdname".sh

declare -r -i argcount="${#@}"

if (( argcount != 0 )) ; then
    "$cmdname" $wait "$@"
else
    "$cmdname" $wait
fi
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature
Type: application/pgp-signature
Size: 236 bytes
Desc: OpenPGP digital signature
URL: <https://cygwin.com/pipermail/cygwin/attachments/20230315/097bf698/attachment-0001.sig>


More information about the Cygwin mailing list