zsh-users
 help / color / mirror / code / Atom feed
* function to run vim
@ 2013-11-13 11:18 shawn wilson
  2013-11-13 17:13 ` Bart Schaefer
  0 siblings, 1 reply; 3+ messages in thread
From: shawn wilson @ 2013-11-13 11:18 UTC (permalink / raw)
  To: Zsh Users

A while I made a function so that I could keep one vim session (gvim
really) and that running 'vim file' would open the file in a new tab
in that session. Recently, it has stopped working.and I'm not sure
why. I get this:
vim --servername SWILSON --remote-tab  file
vimfunc:71: command not found: vim --servername SWILSON --remote-tab  file

which is just ${=cmd} which should run the command?


vimfunc () {
    local cmd
    local servername
    local remote
    local misc
    local version

    local username=$(echo $USER | tr "[:lower:]" "[:upper:]")

    local opt_ex="^-"

    while [ $# -gt 0 ] ; do
        case "$1" in
            --servername)
                if [[ $2 =~ $opt_ex ]] ; then
                    echo "Servername option without a parameter. Doing nothing."
                    return
                else
                    servername="$2"
                    shift
                fi
                ;;
            --remote*)
                if [ -z $remote ] ; then
                    if [[ $2 =~ $opt_ex ]] ; then
                        remote="$1"
                    else
                        remote="$1 $2"
                        shift
                    fi
                else
                    # I'll deal with this properly if it is reasonable
to take multiple --remote* things
                    echo "Should not call two remote options at once.
Doing nothing."
                    return
                fi
                ;;
            --version*)
                version="1"
                ;;
            *)
                misc="$misc $1"
                ;;
        esac
        shift
    done

    cmd="vim"

    if [ ! -z $servername ] ; then
        cmd="$cmd --servername $servername"
    else
        cmd="$cmd --servername $username"
    fi

    if [ -z $misc ] && [ -z $remote ] ; then
        # list version if we asked for that
        if [ ! -z version ] ; then
            cmd="$cmd --version"
        fi

        ${=cmd}
        return
    fi

    if [ ! -z $remote ] ; then
        cmd="$cmd $remote $misc"
    else
        cmd="$cmd --remote-tab $misc"
    fi

    echo $cmd
    ${=cmd}
    return
}


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: function to run vim
  2013-11-13 11:18 function to run vim shawn wilson
@ 2013-11-13 17:13 ` Bart Schaefer
  2013-11-14  1:24   ` shawn wilson
  0 siblings, 1 reply; 3+ messages in thread
From: Bart Schaefer @ 2013-11-13 17:13 UTC (permalink / raw)
  To: shawn wilson, Zsh Users

On Nov 13,  6:18am, shawn wilson wrote:
}
} A while I made a function so that I could keep one vim session (gvim
} really) and that running 'vim file' would open the file in a new tab
} in that session. Recently, it has stopped working.and I'm not sure
} why.

What version of zsh is this (and has that changed recently)?  What does

% print $ZSH_PATCHLEVEL

say?

Does the function work if you do NOT pass the --remote-tab option?

Are you running vimfunc via an alias?  If so, does the behavior change
if you actually type out the full command word "vimfunc ..."?

Try "functions -t vimfunc" to enable execution tracing and then run the
function in the way that fails.

By the way, I think you have a typo here:

}         # list version if we asked for that
}         if [ ! -z version ] ; then
}             cmd="$cmd --version"
}         fi

The [ -z version ] is always going to fail.  Needs $version instead.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: function to run vim
  2013-11-13 17:13 ` Bart Schaefer
@ 2013-11-14  1:24   ` shawn wilson
  0 siblings, 0 replies; 3+ messages in thread
From: shawn wilson @ 2013-11-14  1:24 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Zsh Users

OK, as i was writing this response, I figured it out (or the solution
- I'm just guessing at the problem). But, I think some library got
updated and I haven't rebooted / zsh sessions are old. what's weird is
that in an old session, I show the same ZSH_PATCHLEVEL as in a new
one. I'll have to see if I can figure out what libraries running
processes are linked against...

Thanks for the reply

On Wed, Nov 13, 2013 at 12:13 PM, Bart Schaefer
<schaefer@brasslantern.com> wrote:
> On Nov 13,  6:18am, shawn wilson wrote:
> }
> } A while I made a function so that I could keep one vim session (gvim
> } really) and that running 'vim file' would open the file in a new tab
> } in that session. Recently, it has stopped working.and I'm not sure
> } why.
>
> What version of zsh is this (and has that changed recently)?  What does
>
> % print $ZSH_PATCHLEVEL
>
> say?
>

1.5778

> Does the function work if you do NOT pass the --remote-tab option?
>

Didn't test - I assume that would've failed

> Are you running vimfunc via an alias?  If so, does the behavior change
> if you actually type out the full command word "vimfunc ..."?
>

Yeah, it's an alias so that I can do \vim to actually run plain vim.
It does the same thing if I do 'vimfunc file'

> Try "functions -t vimfunc" to enable execution tracing and then run the
> function in the way that fails.
>

That's cool, I'll use that....
 % vim schroot.conf
+vimfunc:1> local cmd
+vimfunc:2> local servername
+vimfunc:3> local remote
+vimfunc:4> local misc
+vimfunc:5> local version
+vimfunc:7> echo swilson
+vimfunc:7> tr '[:lower:]' '[:upper:]'
+vimfunc:7> local 'username=SWILSON'
+vimfunc:9> local 'opt_ex=^-'
+vimfunc:11> [ 1 -gt 0 ']'
+vimfunc:12> case schroot.conf (--servername)
+vimfunc:12> case schroot.conf (--remote*)
+vimfunc:12> case schroot.conf (--version*)
+vimfunc:12> case schroot.conf (*)
+vimfunc:40> misc=' schroot.conf'
+vimfunc:43> shift
+vimfunc:11> [ 0 -gt 0 ']'
+vimfunc:46> cmd=vim
+vimfunc:48> [ '!' -z ']'
+vimfunc:51> cmd='vim --servername SWILSON'
+vimfunc:54> [ -z ' schroot.conf' ']'
+vimfunc:64> [ '!' -z ']'
+vimfunc:67> cmd='vim --servername SWILSON --remote-tab  schroot.conf'
+vimfunc:70> echo 'vim --servername SWILSON --remote-tab  schroot.conf'
vim --servername SWILSON --remote-tab  schroot.conf
+vimfunc:71> 'vim --servername SWILSON --remote-tab  schroot.conf'
vimfunc:71: command not found: vim --servername SWILSON --remote-tab
schroot.conf
+vimfunc:72> return

> By the way, I think you have a typo here:
>
> }         # list version if we asked for that
> }         if [ ! -z version ] ; then
> }             cmd="$cmd --version"
> }         fi
>
> The [ -z version ] is always going to fail.  Needs $version instead.

Good catch - I just put that in for completeness and never tested it (obviously)


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-11-14  1:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-11-13 11:18 function to run vim shawn wilson
2013-11-13 17:13 ` Bart Schaefer
2013-11-14  1:24   ` shawn wilson

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

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 NNTP newsgroup(s).