[Fish-users] Problem with -n in a conditional statement

2014-11-11 Thread Marcin Zajączkowski
Hi, I wanted to write a script which display different prompt for session made through SSH. SSH should set SSH_CLIENT and SSH_TTY variables, so it should be easy to check. Unfortunately I am unable to write working if for those two cases. In the end it seem that even simple test with “-n” from

Re: [Fish-users] Problem with -n in a conditional statement

2014-11-11 Thread Glenn Jackman
You might want to test if the variable is set first: $ function ntest if not set -q NOT_SET_VARIABLE echo not set else if test -n $NOT_SET_VARIABLE echo Non-zero echo $NOT_SET_VARIABLE else echo Zero

Re: [Fish-users] Problem with -n in a conditional statement

2014-11-11 Thread Marcin Zajączkowski
On 2014-11-11 22:49, Glenn Jackman wrote: You might want to test if the variable is set first: Thanks Glenn, that works. The next problem I encounter is how to check two variables in one if statement. I tried with |and| keyword and with |test| joined with |-a|, but it fails? |if set -q SSH_TTY

Re: [Fish-users] Problem with -n in a conditional statement

2014-11-11 Thread Greg Reagle
That's very interesting. I get the same problem. I don't think anything is wrong with your code. I think something fishy is going on with fish, but I don't know what. It looks like it might even be a bug in fish. I would expect test -n to be the opposite of test -z, but that is not true

[Fish-users] Fwd: Re: Problem with -n in a conditional statement

2014-11-11 Thread Greg Reagle
Forgot to send to the list. - Original message - From: Greg Reagle greg.rea...@umbc.edu To: Marcin Zajączkowski msz...@wp.pl Subject: Re: [Fish-users] Problem with -n in a conditional statement Date: Tue, 11 Nov 2014 17:44:37 -0500 On Tue, Nov 11, 2014, at 05:29 PM, Marcin Zajączkowski

Re: [Fish-users] Problem with -n in a conditional statement

2014-11-11 Thread Glenn Jackman
I suspect what is happening (this is true in bash, I'm speculating about fish) is that an unset variable is substituted with nothing (not the empty string, but with nothing). Then the `test` command receives exactly one argument: -n. When `test` is given a single argument, the result is true if

Re: [Fish-users] Setting true/false to a variable

2014-11-11 Thread Greg Reagle
On Tue, Nov 11, 2014, at 05:45 PM, Marcin Zajączkowski wrote: Another question related to fish scripting. How can I set a value to a variable to be able to use it in `if`? if test $myBool ... end The shell's only notion of true and false (this is true for all unix shells that I know) is

Re: [Fish-users] Problem with -n in a conditional statement

2014-11-11 Thread Marcin Zajączkowski
On 2014-11-11 23:44, Greg Reagle wrote: On Tue, Nov 11, 2014, at 05:29 PM, Marcin Zajączkowski wrote: The next problem I encounter is how to check two variables in one if statement. There are several ways of doing this. Here is one: set -q $COLUMNS $LINES; if test $status = 2; echo

Re: [Fish-users] Problem with -n in a conditional statement

2014-11-11 Thread Glenn Jackman
Marcin, applying this to the 2-variable question: $ test $SSH_TTY$SSH_CLIENT; and echo not empty; or echo unset or empty unset or empty $ ssh localhost [...] $ test $SSH_TTY$SSH_CLIENT; and echo not empty; or echo unset or empty not empty On Tue, Nov 11, 2014 at 5:51 PM, Glenn Jackman

Re: [Fish-users] Fwd: Re: Problem with -n in a conditional statement

2014-11-11 Thread Greg Reagle
Well I was totally wrong here. Of course this is not a bug in fish or the man page, it is my mistake. I shouldn't have used the dollar sign in set -q. Here is corrected code: if set -q COLUMNS LINES; echo both defined; end On Tue, Nov 11, 2014, at 05:45 PM, Greg Reagle wrote: Forgot to

Re: [Fish-users] Problem with -n in a conditional statement

2014-11-11 Thread Marcin Zajączkowski
On 2014-11-11 23:54, Glenn Jackman wrote: Marcin, applying this to the 2-variable question: $ test $SSH_TTY$SSH_CLIENT; and echo not empty; or echo unset or empty unset or empty $ ssh localhost [...] $ test $SSH_TTY$SSH_CLIENT; and echo not empty; or echo unset or empty not empty Nice

Re: [Fish-users] Problem with -n in a conditional statement

2014-11-11 Thread Marcin Zajączkowski
On 2014-11-12 00:03, Marcin Zajączkowski wrote: On 2014-11-11 23:54, Glenn Jackman wrote: Marcin, applying this to the 2-variable question: $ test $SSH_TTY$SSH_CLIENT; and echo not empty; or echo unset or empty unset or empty $ ssh localhost [...] $ test $SSH_TTY$SSH_CLIENT; and echo not

Re: [Fish-users] Problem with -n in a conditional statement

2014-11-11 Thread Greg Reagle
On Tue, Nov 11, 2014, at 05:51 PM, Glenn Jackman wrote: I suspect what is happening (this is true in bash, I'm speculating about fish) is that an unset variable is substituted with nothing (not the empty string, but with nothing). Then the `test` command receives exactly one argument: -n.

Re: [Fish-users] extension exclusion in auto-completion

2014-11-11 Thread Booker Bense
Just to be clear, it's relatively straightforward to write your own custom completions in fish. There just isn't one yet that makes the distinction that you want. You can create your own expansion functions in ~/.config/fish/functions and your own gvim completetions in

Re: [Fish-users] Problem with -n in a conditional statement

2014-11-11 Thread David Adam
On Tue, 11 Nov 2014, Greg Reagle wrote: That's very interesting. I get the same problem. I don't think anything is wrong with your code. I think something fishy is going on with fish, but I don't know what. It looks like it might even be a bug in fish. I would expect test -n to be the