Skip to content

Commit

Permalink
feat: support install by antigen, remove doc on obsolete `unsafe-perm…
Browse files Browse the repository at this point in the history
…` flag
  • Loading branch information
zthxxx committed Jun 16, 2022
1 parent e269d50 commit db717e0
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 23 deletions.
14 changes: 6 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ A plugin that **enhances zsh history search interaction**, with review and choos

## Install

### antigen

```bash
antigen bundle zthxxx/zsh-history-enquirer
```

### oh-my-zsh

If you are using [`oh-my-zsh`](https://github.com/robbyrussell/oh-my-zsh), **all you need to do is one npm command.**
Expand All @@ -42,14 +48,6 @@ npm i -g zsh-history-enquirer

The install/uninstall hooks will be correctly setup in your `oh-my-zsh` plugins and config. Manually editing `.zshrc` is **no longer necessary**

### root

For **root**, you must use the `--unsafe-perm` option for `npm`.

```bash
# https://stackoverflow.com/questions/49084929/npm-sudo-global-installation-unsafe-perm
npm i -g zsh-history-enquirer --unsafe-perm
```

### one-line command

Expand Down
16 changes: 16 additions & 0 deletions init.zsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# for antigen bundle init pipepine
# https://github.com/zsh-users/antigen/blob/v2.2.3/bin/antigen.zsh#L518
#
# install by npm, but do not run npm postinstall

# `zsh-history-enquirer` is also the bin name of package
if [[ ! -e $commands[zsh-history-enquirer] ]]; then
if [[ ! -e $commands[npm] ]]; then
echo 'Cannot install `zsh-history-enquirer` due to not found `npm`.' >&2
else
export _INIT_ZSH_HISTORY_ENQUIRER_INSTALL=true
npm i -g zsh-history-enquirer
fi
fi


6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "zsh-history-enquirer",
"version": "1.2.5",
"version": "1.3.0",
"description": "zsh history search plugin by enquirer",
"main": "index.js",
"bin": {
"fcenquire": "bin/index.js"
"zsh-history-enquirer": "bin/index.js"
},
"scripts": {
"clean": "rimraf dist public coverage debug.log",
Expand Down Expand Up @@ -56,7 +56,9 @@
"scripts",
"bin",
"dist",
"index.js"
"index.js",
"init.zsh",
"zsh-history-enquirer.plugin.zsh"
],
"devDependencies": {
"@commitlint/cli": "8.3.6",
Expand Down
6 changes: 1 addition & 5 deletions scripts/installer.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,4 @@ if [[ ! $commands[node] ]]; then
nvm use default
fi

# access to install for root
# use `--unsafe-perm` for compatible with npm@6 in root
# https://stackoverflow.com/questions/49084929/npm-sudo-global-installation-unsafe-perm
# https://docs.npmjs.com/cli/v6/using-npm/config#unsafe-perm
npm i -g ${package_name} --unsafe-perm
npm i -g ${package_name}
10 changes: 9 additions & 1 deletion scripts/postinstall.zsh
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
#!/usr/bin/env zsh

if [[ -n ${_INIT_ZSH_HISTORY_ENQUIRER_INSTALL} ]]; then
# means the install called by `init.zsh` maybe via `antigen`,
# so, no need to modify any config file

exit 0
fi


if [[ -z $ZSH ]]; then
echo "
\e[33m
Expand All @@ -15,7 +23,7 @@ local plugins_dir="${ZSH_CUSTOM:-"${ZSH}/custom"}/plugins"

mkdir -p ${plugins_dir}/${package_name}

ln -fs "`pwd`/scripts/${package_name}.plugin.zsh" "${plugins_dir}/${package_name}/"
ln -fs "`pwd`/${package_name}.plugin.zsh" "${plugins_dir}/${package_name}/"

# it's same as `realpath`, but `realpath` is GNU only and not builtin
prel-realpath() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# replace '^R' search of zsh-history-enquirer in zsh

function history_enquire() {
# fcenquire is the bin name of zsh-history-enquirer
if [[ -e $commands[fcenquire] ]]; then
BUFFER=$(fcenquire "$LBUFFER")
# `zsh-history-enquirer` is also the bin name of package
if [[ -e $commands[zsh-history-enquirer] ]]; then
BUFFER=$(zsh-history-enquirer "$LBUFFER")
CURSOR=$#BUFFER
zle -R -c
else
Expand Down

0 comments on commit db717e0

Please sign in to comment.