Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
oh-my-zsh
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
github
oh-my-zsh
Commits
ce9104c4
Unverified
Commit
ce9104c4
authored
Dec 29, 2021
by
Alex Matheson
Committed by
GitHub
Dec 29, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(npm): toggle `npm install` / `npm uninstall` by pressing F2 twice (#9717)
Co-authored-by:
Marc Cornellà
<
hello@mcornella.com
>
parent
2acb3071
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
57 additions
and
0 deletions
+57
-0
README.md
plugins/npm/README.md
+17
-0
npm.plugin.zsh
plugins/npm/npm.plugin.zsh
+40
-0
No files found.
plugins/npm/README.md
View file @
ce9104c4
...
...
@@ -29,3 +29,20 @@ plugins=(... npm)
|
`npmI`
|
`npm init`
| Run npm init |
|
`npmi`
|
`npm info`
| Run npm info |
|
`npmSe`
|
`npm search`
| Run npm search |
## `npm install` / `npm uninstall` toggle
The plugin adds a function that toggles between
`npm install`
and
`npm uninstall`
in
the current command or the last command, for up to 2 previous commands.
**
The default
key binding is pressing
<kbd>
F2
</kbd>
twice
**
.
You can change this key binding by adding the following line to your zshrc file:
```
zsh
bindkey
-M
emacs
'<seq>'
npm_toggle_install_uninstall
bindkey
-M
vicmd
'<seq>'
npm_toggle_install_uninstall
bindkey
-M
viins
'<seq>'
npm_toggle_install_uninstall
```
where
`<seq>`
is a key sequence obtained by running
`cat`
and pressing the keyboard
sequence you want.
plugins/npm/npm.plugin.zsh
View file @
ce9104c4
...
...
@@ -69,3 +69,43 @@ alias npmi="npm info"
# Run npm search
alias
npmSe
=
"npm search"
npm_toggle_install_uninstall
()
{
# Look up to the previous 2 history commands
local
line
for
line
in
"
$BUFFER
"
\
"
${
history
[
$((
HISTCMD-1
))
]
}
"
\
"
${
history
[
$((
HISTCMD-2
))
]
}
"
do
case
"
$line
"
in
"npm uninstall"
*
)
BUFFER
=
"
${
line
/npm uninstall/npm install
}
"
((
CURSOR
=
CURSOR + 2
))
# uninstall -> install: 2 chars removed
;;
"npm install"
*
)
BUFFER
=
"
${
line
/npm install/npm uninstall
}
"
((
CURSOR
=
CURSOR + 2
))
# install -> uninstall: 2 chars added
;;
"npm un "
*
)
BUFFER
=
"
${
line
/npm un/npm install
}
"
((
CURSOR
=
CURSOR + 5
))
# un -> install: 5 chars added
;;
"npm i "
*
)
BUFFER
=
"
${
line
/npm i/npm uninstall
}
"
((
CURSOR
=
CURSOR + 8
))
# i -> uninstall: 8 chars added
;;
*
)
continue
;;
esac
return
0
done
BUFFER
=
"npm install"
CURSOR
=
${#
BUFFER
}
}
zle
-N
npm_toggle_install_uninstall
# Defined shortcut keys: [F2] [F2]
bindkey
-M
emacs
'^[OQ^[OQ'
npm_toggle_install_uninstall
bindkey
-M
vicmd
'^[OQ^[OQ'
npm_toggle_install_uninstall
bindkey
-M
viins
'^[OQ^[OQ'
npm_toggle_install_uninstall
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment