Created
June 13, 2011 10:08
-
-
Save amzyang/1022562 to your computer and use it in GitHub Desktop.
remove tabs quickly
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
js <<EOF | |
function removeTabs(count, arg) { | |
let end_pattern = /^[0-9]+$|^(\^|\$)$/; | |
if (!end_pattern.test(arg)) { | |
dactyl.echo("Invalid Range", commandline.FORCE_SINGLELINE) | |
return false; | |
} | |
let end = 0; | |
if (arg == "$") | |
end = tabs.visibleTabs.length; | |
else if (arg == "^") | |
end = -tabs.visibleTabs.length; | |
else | |
end = parseInt(arg); | |
let start = 0; | |
if (typeof count === "object") | |
if (end < start) | |
start = tabs.index(null, true) + 1; | |
else | |
start = tabs.index(null, true); | |
else { | |
start = parseInt(count); | |
if (start != 0) | |
start = parseInt(count) - 1; | |
} | |
let visibleTabs = tabs.visibleTabs; | |
let removedTabs = []; | |
if (start < end ) | |
removedTabs = Array.slice(visibleTabs).slice(start, end); | |
else | |
removedTabs = Array.slice(visibleTabs).slice(end, start); | |
let removedTabs_length = removedTabs.length; | |
removedTabs.forEach(function (aTab) { | |
gBrowser.removeTab(aTab); | |
}); | |
dactyl.echo(removedTabs_length + " tab(s) has been removed!"); | |
} | |
EOF | |
nmap -count -arg -javascript e removeTabs(count, arg) | |
" e$ 删除当前及其右侧所有标签 | |
" e^ 删除当前及其左侧所有标签 | |
" 3e8 从 3 到 8 被删除 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment