Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Merge branch 'master' of https://github.com/xolox/vim-misc
- Loading branch information
Showing
4 changed files
with
106 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,24 @@ | ||
# Miscellaneous auto-load Vim scripts | ||
|
||
The git repository at <http://github.com/xolox/vim-misc> contains Vim scripts | ||
that are used by most of the [Vim plug-ins I've written] [plugins] yet don't | ||
really belong with any single one. I'm hoping to include this repository as a | ||
git submodule in my other repositories so that I only have to maintain these | ||
files in one place. | ||
|
||
For lack of a better place: I hereby release these scripts under the MIT | ||
license, in other words feel free to do with them as you please but don't | ||
misrepresent this work as your own. | ||
The git repository at <http://github.com/xolox/vim-misc> contains Vim scripts that are used by most of the [Vim plug-ins I've written] [plugins] yet don't really belong with any single one. I include this repository as a subdirectory of my plug-in repositories using the following commands: | ||
|
||
$ git remote add -f vim-misc https://github.com/xolox/vim-misc.git | ||
$ git merge -s ours --no-commit vim-misc/master | ||
$ git read-tree --prefix=autoload/xolox/misc/ -u vim-misc/master | ||
$ git commit -m "Merge vim-misc repository as subdirectory" | ||
|
||
To update a plug-in repository to the latest versions of the miscellaneous auto-load scripts I execute the following command: | ||
|
||
$ git pull -s subtree vim-misc master | ||
|
||
## Contact | ||
|
||
If you have questions, bug reports, suggestions, etc. the author can be contacted at <peter@peterodding.com>. The latest version is available at <http://peterodding.com/code/vim/misc> and <http://github.com/xolox/vim-misc>. | ||
|
||
## License | ||
|
||
This software is licensed under the [MIT license](http://en.wikipedia.org/wiki/MIT_License). | ||
© 2011 Peter Odding <<peter@peterodding.com>>. | ||
|
||
|
||
[plugins]: http://peterodding.com/code/vim/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
" Vim auto-load script | ||
" Author: Peter Odding <peter@peterodding.com> | ||
" Last Change: June 18, 2011 | ||
" URL: http://peterodding.com/code/vim/misc/ | ||
|
||
if !exists('s:version') | ||
let s:version = '1.0' | ||
let s:enoimpl = "open.vim %s: %s() hasn't been implemented for your platform! If you have suggestions, please contact peter@peterodding.com." | ||
let s:handlers = ['gnome-open', 'kde-open', 'exo-open', 'xdg-open'] | ||
endif | ||
|
||
function! xolox#misc#open#file(path, ...) | ||
if xolox#misc#os#is_win() | ||
try | ||
call xolox#shell#open_with_windows_shell(a:path) | ||
catch /^Vim\%((\a\+)\)\=:E117/ | ||
let command = '!start CMD /C START "" %s' | ||
silent execute printf(command, shellescape(a:path)) | ||
endtry | ||
return | ||
elseif has('macunix') | ||
let cmd = 'open ' . shellescape(a:path) . ' 2>&1' | ||
call s:handle_error(cmd, system(cmd)) | ||
return | ||
else | ||
for handler in s:handlers + a:000 | ||
if executable(handler) | ||
call xolox#misc#msg#debug("open.vim %s: Using '%s' to open '%s'.", s:version, handler, a:path) | ||
let cmd = shellescape(handler) . ' ' . shellescape(a:path) . ' 2>&1' | ||
call s:handle_error(cmd, system(cmd)) | ||
return | ||
endif | ||
endfor | ||
endif | ||
throw printf(s:enoimpl, s:script, 'xolox#misc#open#file') | ||
endfunction | ||
|
||
function! xolox#misc#open#url(url) | ||
let url = a:url | ||
if url !~ '^\w\+://' | ||
if url !~ '@' | ||
let url = 'http://' . url | ||
elseif url !~ '^mailto:' | ||
let url = 'mailto:' . url | ||
endif | ||
endif | ||
if has('unix') && !has('gui_running') && $DISPLAY == '' | ||
for browser in ['lynx', 'links', 'w3m'] | ||
if executable(browser) | ||
execute '!' . browser fnameescape(url) | ||
call s:handle_error(browser . ' ' . url, '') | ||
return | ||
endif | ||
endfor | ||
endif | ||
call xolox#misc#open#file(url, 'firefox', 'google-chrome') | ||
endfunction | ||
|
||
function! s:handle_error(cmd, output) | ||
if v:shell_error | ||
let message = "open.vim %s: Failed to execute program! (command line: %s%s)" | ||
let output = strtrans(xolox#misc#str#trim(a:output)) | ||
if output != '' | ||
let output = ", output: " . string(output) | ||
endif | ||
throw printf(message, s:version, a:cmd, output) | ||
endif | ||
endfunction | ||
|
||
" vim: et ts=2 sw=2 fdm=marker |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
" Vim auto-load script | ||
" Author: Peter Odding <peter@peterodding.com> | ||
" Last Change: March 15, 2011 | ||
" Last Change: June 14, 2011 | ||
" URL: http://peterodding.com/code/vim/misc/ | ||
|
||
" Trim whitespace from start and end of string. | ||
|
||
function! xolox#misc#str#trim(s) | ||
return substitute(a:s, '^\s*\(.\{-}\)\s*$', '\1', '') | ||
return substitute(a:s, '^\_s*\(.\{-}\)\_s*$', '\1', '') | ||
endfunction | ||
|
||
" vim: ts=2 sw=2 et |