Skip to content

Commit fa0c25b

Browse files
committed
skim can be used instead of fzf
1 parent 7a5ad90 commit fa0c25b

File tree

4 files changed

+37
-7
lines changed

4 files changed

+37
-7
lines changed

NEWS.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Changed
1010

1111
- vpy and vpyshebang now resolve any symlinks in the script path
1212
before determining the projdir and venv path.
13+
- ``sk`` (skim) may now be used instead of ``fzf``
1314

1415
0.3.8
1516
=====

doc/src/deps.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Dependencies
22

3-
The primary requirements are Zsh, Python, and [`fzf`](https://github.com/junegunn/fzf),
3+
The primary requirements are Zsh, Python, and
4+
[`fzf`](https://github.com/junegunn/fzf) *or* [`sk` (skim)](https://github.com/lotabout/skim),
45
with optional additions for more colorful output, alternative json parsers, and faster performance.
56

67
## Suggested Dependencies by Platform
@@ -47,7 +48,7 @@ with optional additions for more colorful output, alternative json parsers, and
4748

4849
- [Zsh](https://repology.org/project/zsh/versions)
4950
- [Python](https://repology.org/project/python/versions)
50-
- [`fzf`](https://github.com/junegunn/fzf)
51+
- [`fzf`](https://github.com/junegunn/fzf) *or* [`sk` (skim)](https://github.com/lotabout/skim)
5152

5253
=== "The optional ones"
5354

doc/src/start.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
## Install locally
88

99
Aside from Zsh and Python, the only dependency you're likely to *need* is
10-
[`fzf`](https://github.com/junegunn/fzf).
10+
[`fzf`](https://github.com/junegunn/fzf) *or* [`sk` (skim)](https://github.com/lotabout/skim).
1111
For more details and recommended package manager commands, see [Dependencies](deps.md).
1212

1313
To install `zpy` itself, you only need to source the file `zpy.plugin.zsh`

zpy.plugin.zsh

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -271,12 +271,34 @@ ZPY_PROCS=${${$(nproc 2>/dev/null):-$(sysctl -n hw.logicalcpu 2>/dev/null)}:-4}
271271
REPLY="${ZPY_VENVS_HOME}/${REPLY}"
272272
}
273273

274+
.zpy_fzf_cmd () {
275+
emulate -L zsh
276+
unset REPLY
277+
278+
local fzf_cmd=fzf
279+
if (( $+commands[fzf] )) {
280+
REPLY=fzf
281+
} elif (( $+commands[sk] )) {
282+
REPLY=sk
283+
} else {
284+
.zpy_log error \
285+
'zpy selection operations require a filter tool' 'Any one of:' \
286+
'- fzf' \
287+
'- sk (skim)'
288+
.zpy_log tip Suggestion "Install fzf with your distro's package manager."
289+
return 1
290+
}
291+
}
292+
274293
.zpy_chooseproj () { # [--multi]
275294
emulate -L zsh
276295
[[ $ZPY_VENVS_HOME ]] || return
277296

278297
# TODO: should this absorb .zpy_pipzchoosepkg?
279298

299+
.zpy_fzf_cmd || return
300+
local fzf_cmd=$REPLY
301+
280302
local multi fzf_args=(--reverse -0 --preview='<{}/*.in')
281303
if [[ $1 == --multi ]] {
282304
unset reply
@@ -291,7 +313,7 @@ ZPY_PROCS=${${$(nproc 2>/dev/null):-$(sysctl -n hw.logicalcpu 2>/dev/null)}:-4}
291313
local projdirs=(${ZPY_VENVS_HOME}/*/project(@N-/:P))
292314
reply=(${(f)"$(
293315
print -rln -- $projdirs \
294-
| fzf $fzf_args
316+
| $fzf_cmd $fzf_args
295317
)"})
296318

297319
[[ $reply ]] || return
@@ -1827,6 +1849,9 @@ jsonfile.write_text(dumps(data, indent=4))
18271849
# TODO: fzf OR skim OR fzy OR peco
18281850
[[ -r $ZPY_SRC ]] || return
18291851

1852+
.zpy_fzf_cmd || return
1853+
local fzf_cmd=$REPLY
1854+
18301855
local fzf_args=() fzf_header fzf_prompt multi
18311856
fzf_args=(--reverse -0)
18321857
fzf_header='Packages:'
@@ -1856,7 +1881,7 @@ jsonfile.write_text(dumps(data, indent=4))
18561881

18571882
local pkgs=($1/*(N/:t))
18581883
reply=(${(f)"$(
1859-
print -rln -- $pkgs | fzf $fzf_args
1884+
print -rln -- $pkgs | $fzf_cmd $fzf_args
18601885
)"})
18611886

18621887
[[ $reply ]] || return
@@ -1919,7 +1944,7 @@ jsonfile.write_text(dumps(data, indent=4))
19191944

19201945
zf_mkdir -p $bins_home
19211946

1922-
local pkgname projdir vpath bins bin src dest REPLY
1947+
local pkgname projdir vpath bins bin src dest REPLY fzf_cmd
19231948
for 1 {
19241949
.zpy_pkgspec2name $1 || return
19251950
pkgname=$REPLY
@@ -1933,6 +1958,9 @@ jsonfile.write_text(dumps(data, indent=4))
19331958
if [[ $bins_showlist ]] {
19341959
bins=(${bins:*bins_showlist})
19351960
} else {
1961+
.zpy_fzf_cmd || return
1962+
fzf_cmd=$REPLY
1963+
19361964
bins=(${bins:|bins_hidelist})
19371965
bins=(${bins:#([aA]ctivate(|.csh|.fish|.ps1|.bat|.nu|_this.py)|(deactivate|pydoc).bat|easy_install(|-<->*)|(pip|python|pypy)(|<->*)|*.so|__pycache__)})
19381966
if [[ $pkgname != pip-tools ]] bins=(${bins:#pip-(compile|sync)})
@@ -1941,7 +1969,7 @@ jsonfile.write_text(dumps(data, indent=4))
19411969
if [[ $pkgname != build ]] bins=(${bins:#pyproject-build})
19421970
bins=(${(f)"$(
19431971
print -rln $bins \
1944-
| fzf $fzf_args --header="$fzf_header $1 . . ." \
1972+
| $fzf_cmd $fzf_args --header="$fzf_header $1 . . ." \
19451973
--prompt='Which scripts should be added to the path? Choose one with <enter> or more with <tab>. '
19461974
)"})
19471975
}

0 commit comments

Comments
 (0)