hari
hari

Reputation: 1439

Translating Cygwin path to Windows

HI, I have cygwin installed in my Windows system. I have written two function in my profile file so that every time I open vi/vim, it will open with gvim.

But with this one of the issue, the windows path and Cygwin path. I tried with Cygpath as below:

function vi () 
{ 
    win_file_path=$(cygpath -w $*)
    gvim "$win_file_path" & 
}

Bu with this, when ever I open a file like this: "vi /etc/exports +5", it will result in error. So let me know if any of you have any solution.

Upvotes: 1

Views: 819

Answers (2)

Luc Hermitte
Luc Hermitte

Reputation: 32936

cyg-wrapper has been written for this sole purpose.

NB: See also the related wikia page.

Upvotes: 1

sehe
sehe

Reputation: 392999

You can treat the file arguments only:

function vi ()  
{   
    local -a viargs
    local a
    while [[ $# -gt 0 ]]
    do
        a="$1"
        if [ -e "$a" ]; then a="$(cygpath -w "$a")"; fi
        viargs[${#viargs[@]}]="$a"
        shift
    done
    gvim "${viargs[@]}" &  
}

Instead of being 'smart' about existing files like this, feel free to simplify to treat just the first argument :)

In recent bash versions you can replace the ugly line

        viargs[${#viargs[@]}]="$a"

with

        viargs+=( "$a" )

Upvotes: 1

Related Questions