7200fd1fb402

Initial commit.
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Tue, 03 Apr 2012 13:18:05 -0400
parents
children 8ba0b710ddf5
branches/tags (none)
files README.markdown doc/clam.txt package.sh plugin/clam.vim

Changes

--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/README.markdown	Tue Apr 03 13:18:05 2012 -0400
@@ -0,0 +1,18 @@
+Clam
+====
+
+Clam.vim is a lightweight Vim plugin to easily run shell commands.
+
+Installation and Usage
+----------------------
+
+Use Pathogen to install.
+
+[Read the docs][docs] for more information.
+
+[docs]: http://vim-doc.heroku.com/view?https://raw.github.com/sjl/clam.vim/master/doc/clam.txt
+
+License
+-------
+
+MIT/X11.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/doc/clam.txt	Tue Apr 03 13:18:05 2012 -0400
@@ -0,0 +1,96 @@
+*clam.txt*   easily work with shell commands
+
+                         ___  __      __    __  __
+                        / __)(  )    /__\  (  \/  )
+                       ( (__  )(__  /(__)\  )    (
+                        \___)(____)(__)(__)(_/\/\_)
+
+          A lightweight Vim plugin for working with shell commands.
+
+==============================================================================
+CONTENTS                                                       *clam-contents*
+
+    1. Usage ........................... |ClamUsage|
+    2. Mappings ........................ |ClamMappings|
+        2.1 Refresh .................... |ClamRefresh|
+        2.2 Pipe ....................... |ClamPipe|
+    3. License ......................... |ClamLicense|
+    4. Bugs ............................ |ClamBugs|
+    5. Contributing .................... |ClamContributing|
+    6. Changelog ....................... |ClamChangelog|
+
+==============================================================================
+1. Usage                                                           *ClamUsage*
+
+The :Clam command is your point of entry to Clam.  Use it to run a shell
+command like this: >
+
+    :Clam ls -l
+
+This will open up a new vertical split with the results of the command in it.
+You can edit the text in this split like any other buffer.
+
+When you close the buffer with :quit or something similar Clam will place your
+cursor back in the split you came from.
+
+You might want to set up your own mapping to make Clam easier to use.  The
+author has something like this in his .vimrc: >
+
+    nnoremap ! :Clam<space>
+
+That's Clam in a nutclamshell.
+
+==============================================================================
+2. Mappings                                                     *ClamMappings*
+
+Clam also defines two special mappings in the command output window for your
+convenience.
+
+------------------------------------------------------------------------------
+2.1 Refresh                                                      *ClamRefresh*
+
+Bound to: <localleader>r
+
+"Refresh" the output by running the command again.
+
+This is useful for commands where the output might change frequently and you
+want to watch it in real time.
+
+------------------------------------------------------------------------------
+2.2 Pipe                                                            *ClamPipe*
+
+Bound to: <localleader>p
+
+"Pipe" the buffer through another command and replace the contents with its
+result.
+
+This allows you to run a shell pipeline where you can manually inspect and
+massage the intermediate results.
+
+==============================================================================
+3. License                                                       *ClamLicense*
+
+Clam is MIT/X11 licensed.
+
+==============================================================================
+4. Bugs                                                             *ClamBugs*
+
+If you find a bug please post it on the issue tracker:
+http://github.com/sjl/clam.vim/issues/
+
+==============================================================================
+5. Contributing                                             *ClamContributing*
+
+Think you can make this plugin better?  Awesome!  Fork it on BitBucket or
+GitHub and send a pull request.
+
+BitBucket: http://bitbucket.org/sjl/clam.vim/
+GitHub: http://github.com/sjl/clam.vim/
+
+==============================================================================
+6. Changelog                                                   *ClamChangelog*
+
+v1.0.0
+    * Initial stable release.
+
+==============================================================================
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/package.sh	Tue Apr 03 13:18:05 2012 -0400
@@ -0,0 +1,3 @@
+#!/usr/bin/env bash
+
+hg archive ~/Desktop/clam.zip -I 'doc' -I 'plugin' -I README.markdown
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/plugin/clam.vim	Tue Apr 03 13:18:05 2012 -0400
@@ -0,0 +1,65 @@
+" ============================================================================
+" File:        clam.vim
+" Description: A simple little shell.
+" Maintainer:  Steve Losh <steve@stevelosh.com>
+" License:     MIT/X11
+" ============================================================================
+
+
+" Init {{{
+
+if !exists('g:clam_debug') && (exists('loaded_clam') || &cp)
+    finish
+endif
+
+let loaded_clam = 1
+
+"}}}
+" Function {{{
+
+function! s:Execlam(command)
+    " Build the actual command string to execute
+    let command = join(map(split(a:command), 'expand(v:val)'))
+
+    " Find any already-open clam windows for this command.
+    let winnr = bufwinnr('^' . command . '$')
+
+    " Open the new window (or move to an existing one).
+    if winnr < 0
+        silent! execute 'botright vnew ' . fnameescape(command)
+    else
+        silent! execute winnr . 'wincmd w'
+    endif
+
+    " Set some basic options for the output window.
+    setlocal buftype=nowrite bufhidden=wipe nobuflisted noswapfile nowrap nonumber
+
+    " Actually run the command, placing its output in the current window.
+    echo 'Executing: ' . command
+    silent! execute 'silent %!'. command
+
+    " When closing this buffer in any way (like :quit), jump back to the original window.
+    silent! execute 'au BufUnload <buffer> execute bufwinnr(' . bufnr('#') . ') . ''wincmd w'''
+
+    " Map <localleader>r to "refresh" the command (call it again).
+    silent! execute 'nnoremap <silent> <buffer> <LocalLeader>r :call <SID>ExecuteInShell(''' . command . ''')<CR>:AnsiEsc<CR>'
+
+    " Map <localleader>p to "pipe" the buffer into a new command.
+    silent! execute 'nnoremap <buffer> <LocalLeader>p ggVG!'
+
+    " Highlight ANSI color codes if the AnsiEsc plugin is present.
+    if exists("g:loaded_AnsiEscPlugin")
+        silent! execute 'AnsiEsc'
+    endif
+
+    silent! redraw
+
+    echo 'Shell command executed: ' . command
+endfunction
+
+" }}}
+" Command {{{
+
+command! -complete=shellcmd -nargs=+ Clam call s:Execlam(<q-args>)
+
+" }}}