aboutsummaryrefslogtreecommitdiff
path: root/external/zsh/aliases/npm.zsh
diff options
context:
space:
mode:
Diffstat (limited to 'external/zsh/aliases/npm.zsh')
-rw-r--r--external/zsh/aliases/npm.zsh20
1 files changed, 20 insertions, 0 deletions
diff --git a/external/zsh/aliases/npm.zsh b/external/zsh/aliases/npm.zsh
new file mode 100644
index 0000000..efc8ec7
--- /dev/null
+++ b/external/zsh/aliases/npm.zsh
@@ -0,0 +1,20 @@
+
+# Node aliases
+alias nr="npm run";
+alias ns="npm start";
+alias nt="npm test";
+
+run_npm_script() {
+ [[ ! -f "package.json" ]] && return 1;
+
+ local commands=$(node -e 'const pkg = require("./package.json"); Object.entries(pkg.scripts || {}).map(([key, value]) => console.log(`${key}\t\t "${value}"`))');
+
+ local result=$(echo -e "$commands" | fzf | cut -f1);
+
+ [[ -z "$result" ]] && return 1;
+ yarn "$result";
+}
+
+zle -N run_npm_script;
+bindkey '^B' run_npm_script;
+