public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Sam Edge <sam.edge@gmx.com>
To: cygwin@cygwin.com
Subject: Re: exe in path directory, "command not found"
Date: Wed, 15 Mar 2023 07:27:16 +0000	[thread overview]
Message-ID: <9667701c-6b2e-563d-0980-34939e1f8042@gmx.com> (raw)
In-Reply-To: <5qX4xu9puPlJx_NA1mLmAZHSRFqMNOeQc7F2TddnyUMnEkBqGYqoeBrooBc-gc1WHWtQhDNPzg_la1O2qRZPv9jFoZ5-zQJ-xaMU7uvW4Iw=@proton.me>


[-- Attachment #1.1.1: Type: text/plain, Size: 1122 bytes --]

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


[-- Attachment #1.1.2: zzzz_91.npp.sh --]
[-- Type: text/plain, Size: 3751 bytes --]

#!/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
}

[-- Attachment #1.1.3: npp --]
[-- Type: text/plain, Size: 782 bytes --]

#!/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

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 236 bytes --]

      parent reply	other threads:[~2023-03-15  7:27 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-15  3:00 WyntrHeart
2023-03-15  3:07 ` Eliot Moss
2023-03-15  3:27 ` René Berber
2023-03-15  3:27   ` René Berber
2023-03-15  7:27 ` Sam Edge [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9667701c-6b2e-563d-0980-34939e1f8042@gmx.com \
    --to=sam.edge@gmx.com \
    --cc=cygwin@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).