Created
April 9, 2009 00:43
-
-
Save erickedji/92148 to your computer and use it in GitHub Desktop.
ubiquity: strip '$' in shell snippets
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
/* | |
* Strip the characters of the modifier in the input | |
* This was motivated by the desire to strip '$'s in shell snippets, | |
* so as to copy and paste in a running terminal. | |
* TODO: Add support for stripping 'eric@schemer$ ' for example. | |
* | |
* Eric KEDJI <eric.kedji@gmail.com> | |
*/ | |
CmdUtils.CreateCommand({ | |
name: "strip", | |
homepage: "http://erickedji.wordpress.com/", | |
author: {name: "Eric", email: "eric.kedji@gmail.com"}, | |
license: "GPL", | |
description: "Strip the characters of the modifier in the input", | |
help: "Invoke it on a chunk of text", | |
takes: {"input": /.*/}, | |
modifiers: {"all": /[^ ]+/}, | |
preview: function(pblock, input) { | |
pblock.innerHTML = "Strip characters."; | |
}, | |
execute: function(input, mod) { | |
var str = input.text; | |
var chars = mod.all.text; | |
for (i = 0; i < chars.length; i++) { | |
str = str.replace(new RegExp(chars[i], 'g'), ''); | |
} | |
CmdUtils.setSelection(str); | |
} | |
}); | |
CmdUtils.CreateCommand({ | |
name: "strip-ws", | |
homepage: "http://erickedji.wordpress.com/", | |
author: {name: "Eric", email: "eric.kedji@gmail.com"}, | |
license: "GPL", | |
description: "Strip white space in the input", | |
help: "Invoke it on a chunk of text", | |
takes: {"input": /.*/}, | |
preview: function(pblock, input) { | |
pblock.innerHTML = "Strip characters."; | |
}, | |
execute: function(input, mod) { | |
var str = input.text; | |
str = str.replace(new RegExp(' ', 'g'), ''); | |
CmdUtils.setSelection(str); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment