1

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.

hari
  • 1,379
  • 3
  • 16
  • 29

2 Answers2

1

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" )
sehe
  • 328,274
  • 43
  • 416
  • 565
1

cyg-wrapper has been written for this sole purpose.

NB: See also the related wikia page.

Luc Hermitte
  • 29,719
  • 7
  • 60
  • 74