Skip to content

Instantly share code, notes, and snippets.

@jonuts
Created September 1, 2009 04:30
Show Gist options
  • Save jonuts/178899 to your computer and use it in GitHub Desktop.
Save jonuts/178899 to your computer and use it in GitHub Desktop.
ShellFM = function() {
const commands = ['skip', 'love', 'hate', 'pause', 'play'];
var shellsocket = liberator.globalVariables.shellsocket;
var socat = liberator.globalVariables.socat || "/usr/bin/socat";
var runCommand = function(cmd) {
if (!shellsocket){
liberator.echo("Set shellsocket with the path to your shell-fm UNIX socket");
return;
}
var command = "silent !" + socat + " UNIX-CONNECT:" + shellsocket + " - <<<'" + cmd + "'";
liberator.execute(command);
return;
};
return {
skip: function(){ runCommand('skip' ) },
love: function(){ runCommand('love' ) },
hate: function(){ runCommand('ban' ) },
pause: function(){ runCommand('pause') },
play: function(){
var station = prompt("Station to play:");
var cmd = "play lastfm://" + station;
runCommand(cmd);
},
completer: function(context) {
context.completions = [[c, ''] for each (c in commands)];
}
};
}();
commands.add(
['ShellFM'],
'Control shell-fm from within vimperator',
function(cmd) {ShellFM[cmd].call()},
{ count: true, argCount: 1, completer: ShellFM.completer }
);
mappings.add(
[modes.NORMAL],
["<Leader>sl"],
'Love track',
function() {ShellFM.love()}
)
mappings.add(
[modes.NORMAL],
["<Leader>sn"],
'Skip track',
function() {ShellFM.skip()}
)
mappings.add(
[modes.NORMAL],
["<Leader>sp"],
'Skip track',
function() {ShellFM.play()}
)
mappings.add(
[modes.NORMAL],
["<Leader>sP"],
'Skip track',
function() {ShellFM.pause()}
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment