From f354ade247d1cac1c1e5c7075e4a9abce6d13d1c Mon Sep 17 00:00:00 2001 From: Derek Wyatt Date: Fri, 16 Mar 2012 11:22:43 -0400 Subject: [PATCH 1/2] A simple script that prettifies the 'dirs -v' output and provides regex directory switching --- plugins/regex-dirstack/README.md | 36 ++++++++++++++++ .../regex-dirstack/regex-dirstack.plugin.zsh | 42 +++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 plugins/regex-dirstack/README.md create mode 100644 plugins/regex-dirstack/regex-dirstack.plugin.zsh diff --git a/plugins/regex-dirstack/README.md b/plugins/regex-dirstack/README.md new file mode 100644 index 000000000..969e770cc --- /dev/null +++ b/plugins/regex-dirstack/README.md @@ -0,0 +1,36 @@ +## Regex Matching in the Directory Stack for ZSH ## + +Adds `ss` and `csd` to the list of directory manipulation functions. Zsh (or at +least the one I'm using) is mainting the directory stack for me all the time, +but I don't like how it looks when you type type `dirs -v` and I think the whole +`+n` and `-n` thing is just annoying. I also don't know why the current +directory is shown. The current directory is the current directory, so I'm not +interested in it. + +So I've simplified it to look "better" (IMO) with `ss` and the `csd` function +will accept a regular expression. + +Usage: + + # show stack + > ss + 1) ~ + 2) /tmp + 3) /tmp/this/has a/space in it + 4) /tmp/src/main/scala/package/name/here + 5) /tmp/src/test/scala/package/name/here + + # change to stacked directory + > csd 4 + /tmp/src/main/scala/package/name/here + > + + # change to stacked directory by regex + > csd test + /tmp/src/test/scala/package/name/here + > + + # change to stacked directory by more interesting regex + > csd src.*main + /tmp/src/main/scala/package/name/here + > diff --git a/plugins/regex-dirstack/regex-dirstack.plugin.zsh b/plugins/regex-dirstack/regex-dirstack.plugin.zsh new file mode 100644 index 000000000..113610d0f --- /dev/null +++ b/plugins/regex-dirstack/regex-dirstack.plugin.zsh @@ -0,0 +1,42 @@ +function limitStringToWidthByMidpoint +{ + local string="$1" + local width=$2 + if (( ${#string} > $width )); then + local splitnum=$((collimit/2)) + echo "$(echo $string | cut -c1-$splitnum) ... $(echo $string | cut -c$((${#string}-$splitnum))-)" + else + echo $string + fi +} + +function ss +{ + local c=1 + local collimit=$((${COLUMNS-80}-10)) + dirs -p | tail -n+2 | \ + while read f + do + echo "$c) "$(limitStringToWidthByMidpoint $f $collimit) + ((c=c+1)) + done +} + +function csd +{ + local num="${1-}" + + if ! echo "$num" | grep -q '^[0-9][0-9]*$'; then + local re="$num" + local num=$(dirs -p | tail -n+2 | grep -n $re | head | cut -f1 -d:) + if [ -z $num ]; then + echo "'$re' matched nothing" 1>&2 + return 1 + fi + elif [ $num -lt 1 ]; then + echo "usage: csd " 1>&2 + return 1 + fi + cd +$num + return $? +} From be80625369720ce15c1b93d8d05e49092a3e69db Mon Sep 17 00:00:00 2001 From: Derek Wyatt Date: Tue, 20 Mar 2012 08:10:15 -0400 Subject: [PATCH 2/2] A plugin that makes it easier to interact with the (single) running instance of gvim --- plugins/vim-interaction/README.md | 69 +++++++++++++++++++ .../vim-interaction.plugin.zsh | 67 ++++++++++++++++++ 2 files changed, 136 insertions(+) create mode 100644 plugins/vim-interaction/README.md create mode 100644 plugins/vim-interaction/vim-interaction.plugin.zsh diff --git a/plugins/vim-interaction/README.md b/plugins/vim-interaction/README.md new file mode 100644 index 000000000..65e678b51 --- /dev/null +++ b/plugins/vim-interaction/README.md @@ -0,0 +1,69 @@ +# Vim Interaction # + +The plugin presents a function called `callvim` whose usage is: + + usage: callvim [-b cmd] [-a cmd] [file ... fileN] + + -b cmd Run this command in GVIM before editing the first file + -a cmd Run this command in GVIM after editing the first file + file The file to edit + ... fileN The other files to add to the argslist + +## Rationale ## + +The idea for this script is to give you some decent interaction with a running +GVim session. Normally you'll be running around your filesystem doing any +number of amazing things and you'll need to load some files into GVim for +editing, inspecting, destruction, or other bits of mayhem. This script lets you +do that. + +## Aliases ## + +There are a few aliases presented as well: + +* `v` A shorthand for `callvim` +* `vvsp` Edits the passed in file but first makes a vertical split +* `vhsp` Edits the passed in file but first makes a horizontal split + +## Examples ## + +This will load `/tmp/myfile.scala` into the running GVim session: + + > v /tmp/myfile.scala + +This will load it after first doing a vertical split: + + > vvsp /tmp/myfile.scala + or + > v -b':vsp' /tmp/myfile.scala + +This will load it after doing a horizontal split, then moving to the bottom of +the file: + + > vhsp -aG /tmp/myfile.scala + or + > v -b':sp' -aG /tmp/myfile.scala + +This will load the file and then copy the first line to the end (Why you would +ever want to do this... I dunno): + + > v -a':1t$' /tmp/myfile.scala + +And this will load all of the `*.txt` files into the args list: + + > v *.txt + +If you want to load files into areas that are already split, use one of the +aliases for that: + + # Do a ':wincmd h' first + > vh /tmp/myfile.scala + + # Do a ':wincmd j' first + > vj /tmp/myfile.scala + + # Do a ':wincmd k' first + > vk /tmp/myfile.scala + + # Do a ':wincmd l' first + > vl /tmp/myfile.scala diff --git a/plugins/vim-interaction/vim-interaction.plugin.zsh b/plugins/vim-interaction/vim-interaction.plugin.zsh new file mode 100644 index 000000000..3f346dfc3 --- /dev/null +++ b/plugins/vim-interaction/vim-interaction.plugin.zsh @@ -0,0 +1,67 @@ +# +# See README.md +# +# Derek Wyatt (derek@{myfirstnamemylastname}.org +# + +function resolveFile +{ + if [ -f "$1" ]; then + echo $(readlink -f "$1") + else + echo "$1" + fi +} + +function callvim +{ + if [[ $# == 0 ]]; then + cat <} == $after ]]; then + after="$after" + fi + if [[ ${before#:} != $before && ${before%} == $before ]]; then + before="$before" + fi + local files="" + for f in $@ + do + files="$files $(resolveFile $f)" + done + if [[ -n $files ]]; then + files=':args! '"$files" + fi + cmd="$before$files$after" + gvim --remote-send "$cmd" +} + +alias v=callvim +alias vvsp="callvim -b':vsp'" +alias vhsp="callvim -b':sp'" +alias vk="callvim -b':wincmd k'" +alias vj="callvim -b':wincmd j'" +alias vl="callvim -b':wincmd l'" +alias vh="callvim -b':wincmd h'"