.bashrc function is not working on Cygwin

3

1

I recently installed last version of Cygwin. Right now I'm just configuring some alias and functions to use. Cygwin is reading the .bashrc file correctly, because some alias are working, I just have a problem with this function:

sublime () {
    cygstart "c:/Program Files (x86)/Sublime Text 2/sublime_text.exe" "`cygpath -w $1`" 
}

What I'm trying to achieve is that Cygwin let me do something like this:

tom@tom-pc ~
$ sublime myfile.ext

Instead of this:

tom@tom-pc ~
$ cygstart "c:/Program Files (x86)/Sublime Text 2/sublime_text.exe" myfile.ext

How can I solve this problem? I have tried to use single quotes and escape the path string and nothing... Also don't know which programming language is used to execute this functions, so I can't fix this.

Tomás Ramírez

Posted 2012-11-26T02:02:13.947

Reputation: 189

don't forget to quote $1 too: cygstart ... "$(cygpath -w "$1")" – glenn jackman – 2012-11-27T00:07:40.040

yes, I had that issue before ;) – Tomás Ramírez – 2012-11-27T05:51:51.353

Answers

2

Edit: Answer completely revised after comment thread

Looks like the problem is that your .bashrc has two parts separated by [[ "$-" != *i* ]] && return. The first part is executed for all shells, the second part is executed for interactive shells only. The function definition was placed in the second part and thus the function is not defined in non-interactive shells.

Solution: Put sublime () { ... } before the return line.

melpomene

Posted 2012-11-26T02:02:13.947

Reputation:

yes, sorry... the line wasn't complete (check edit) ;) – Tomás Ramírez – 2012-11-26T02:07:39.977

So how does it fail? What's the actual problem? – None – 2012-11-26T02:08:50.870

I'm getting -bash: sublime: couln't find that order on the shell – Tomás Ramírez – 2012-11-26T02:10:31.360

couln't find that order is not a bash error. What's the real error message? – None – 2012-11-26T02:13:33.937

I don't know, I'm working under Windows, and this is a configuration file, but the lines before are working. How can I know the real error? – Tomás Ramírez – 2012-11-26T02:16:33.537

By looking at the terminal and copy/pasting the error message. – None – 2012-11-26T02:17:14.910

.bashrc: line 27: return: only you can use return in a function or I have commented that line: [[ "$-" != *i* ]] && return and is working now! :D – Tomás Ramírez – 2012-11-26T02:25:32.673

Well, that was pointless. For the record, the actual error message was -bash: sublime: command not found (probably in a foreign language and "couln't find that order" was a bad translation attempt). – None – 2012-11-26T02:27:52.370