Skip to content

Instantly share code, notes, and snippets.

@amzyang
Created March 29, 2012 15:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amzyang/2238243 to your computer and use it in GitHub Desktop.
Save amzyang/2238243 to your computer and use it in GitHub Desktop.
use :Dactyl command to control pentadactyl directly in vim
if (!exists('g:firefox_execute') || empty(g:firefox_execute))
let g:firefox_execute = 'firefox'
endif
fun! DactylComplete(A, L, P) "{{{
if (!exists('g:DactylCompleteLoaded'))
let l:tmp = tempname()
let l:getListCommands = 'js let hives = modules.commands.allHives;'
\ .'var names = [];'
\ .'Array.forEach(hives, function(hive) {'
\ .' let lists = hive._list;'
\ .' Array.forEach(lists, function(list) {'
\ .' names = names.concat(list.names);'
\ .' });'
\ .'});'
\ .'names.sort();'
\ .'uniqueNames = names.filter(function(elem, pos) names.indexOf(elem) == pos);'
\ .'names = uniqueNames;'
\ .'var localFile = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);'
\ .'try {'
\ .printf(' localFile.initWithPath("%s");', l:tmp)
\ .' if (!localFile.exists() || (!localFile.isDirectory())) {'
\ .' Components.utils.import("resource://gre/modules/NetUtil.jsm");'
\ .' Components.utils.import("resource://gre/modules/FileUtils.jsm");'
\ .' var ostream = FileUtils.openSafeFileOutputStream(localFile);'
\ .' var converter = Components.classes["@mozilla.org/intl/scriptableunicodeconverter"].createInstance(Components.interfaces.nsIScriptableUnicodeConverter);'
\ .' converter.charset = "UTF-8";'
\ .' var istream = converter.convertToInputStream(names.join("\n"));'
\ .' NetUtil.asyncCopy(istream, ostream, function(status) {'
\ .' if (!Components.isSuccessCode(status)) {'
\ .' return;'
\ .' }'
\ .' });'
\ .' } else {'
\ .' dactyl.echoerr("Unable to save file!");'
\ .' }'
\ .'} catch (e) {'
\ .' dactyl.echoerr("failed!");'
\ ."}"
sil call system(printf("%s -pentadactyl-remote \"%s\"", shellescape(g:firefox_execute, 1), escape(l:getListCommands, "\"")))
try
let g:DactylCommands = readfile(l:tmp)
let g:DactylCompleteLoaded = 1
catch
echoerr "Completion failed, maybe firefox isn't running."
return []
endtry
endif
let l:args = g:DactylCommands
let l:valid_completes = []
for l:arg in l:args
if stridx(l:arg, a:A) == 0
let l:valid_completes += [l:arg]
endif
endfor
return l:valid_completes
endfunction "}}}
" FIXME: :Dactyl echo <></>
" FIXME: let it work on Windows
command! -complete=customlist,DactylComplete -nargs=* Dactyl sil call system(printf("%s -pentadactyl-remote \"%s\"", shellescape(g:firefox_execute, 1), escape(<q-args>, "\"")))
@amzyang
Copy link
Author

amzyang commented Mar 29, 2012

use :Dactyl to run pentadactyl ex commands.

for example:

:Dactyl pwd

You can use 'g:firefox_execute' variable to specify the location of your firefox execute.

@amzyang
Copy link
Author

amzyang commented Mar 29, 2012

Unfortunately, it doesn't work on Windows.

@amzyang
Copy link
Author

amzyang commented Apr 8, 2012

It doesn't work on Mac OS X too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment