Created
February 2, 2012 09:05
-
-
Save Phize/1722473 to your computer and use it in GitHub Desktop.
Vim: switching github accounts for Gist.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
" ************************************************** | |
" Gist {{{ | |
" ************************************************** | |
" dictionary of Gist accounts. | |
let g:gist_accounts = { | |
\ 'user1': { | |
\ 'password': 'password' | |
\ }, | |
\ 'user2': { | |
\ 'password': 'password' | |
\ } | |
\ } | |
" write the configuration file for Gist.vim. | |
function! s:writeGistVimConfig(user, password) | |
let configfile = expand('~/.gist-vim') | |
let secret = printf('basic %s', base64#b64encode(a:user . ':' . a:password)) | |
call writefile([secret], configfile) | |
endfunction | |
" switch Gist account. | |
function! s:switchGistAccount(user) | |
if !exists('g:gist_accounts') || | |
\ !has_key(g:gist_accounts, a:user) || | |
\ !has_key(g:gist_accounts[a:user], 'password') | |
return | |
endif | |
call s:writeGistVimConfig(a:user, g:gist_accounts[a:user].password) | |
endfunction | |
" switch & echo Gist account. | |
function! s:switchAndEchoGistAccount(user) | |
call s:switchGistAccount(a:user) | |
echo 'Gist: ' . a:user | |
endfunction | |
call s:switchGistAccount('user1') | |
" key mapping | |
nnoremap <silent> <Leader>G1 :<C-u>call <SID>switchAndEchoGistAccount('user1')<CR> | |
nnoremap <silent> <Leader>G2 :<C-u>call <SID>switchAndEchoGistAccount('user2')<CR> | |
" }}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment