Skip to content

Commit

Permalink
🎨 Format code
Browse files Browse the repository at this point in the history
Add .editorconfig
Update .pre-commit-config.yaml
Add install methods and optional dependencies to fix #3
Fix some syntax errors
  • Loading branch information
Freed-Wu committed Jan 21, 2023
1 parent 2df0998 commit cffe29e
Show file tree
Hide file tree
Showing 48 changed files with 278 additions and 216 deletions.
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[LICENSE]
indent_size = unset

[Makefile]
indent_style = tab
7 changes: 4 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ repos:
additional_dependencies:
- tomli
- repo: https://github.com/jorisroovers/gitlint
rev: v0.18.0
rev: v0.19.0dev
hooks:
- id: gitlint
args:
Expand All @@ -45,7 +45,7 @@ repos:
hooks:
- id: check-mailmap
- repo: https://github.com/adrienverge/yamllint
rev: v1.28.0
rev: v1.29.0
hooks:
- id: yamllint
- repo: https://github.com/executablebooks/mdformat
Expand All @@ -55,14 +55,15 @@ repos:
args:
- --number
additional_dependencies:
- mdformat-gfm
- mdformat-myst
- mdformat-toc
- mdformat-deflist
- mdformat-beautysh
- mdformat-black
- mdformat-config
- repo: https://github.com/DavidAnson/markdownlint-cli2
rev: v0.5.1
rev: v0.6.0
hooks:
- id: markdownlint-cli2
additional_dependencies:
Expand Down
38 changes: 32 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
[![github/last-commit](https://shields.io/github/last-commit/Freed-Wu/fzf-tab-source)](https://github.com/Freed-Wu/fzf-tab-source/commits)
[![github/release-date](https://shields.io/github/release-date/Freed-Wu/fzf-tab-source)](https://github.com/Freed-Wu/fzf-tab-source/releases/latest)

[![github/license](https://shields.io/github/license/Freed-Wu/fzf-tab-source)](https://github.com/Freed-Wu/fzf-tab-source/blob/master/LICENSE)
[![github/license](https://shields.io/github/license/Freed-Wu/fzf-tab-source)](https://github.com/Freed-Wu/fzf-tab-source/blob/main/LICENSE)
![github/languages](https://shields.io/github/languages/count/Freed-Wu/fzf-tab-source)
![github/languages/top](https://shields.io/github/languages/top/Freed-Wu/fzf-tab-source)
![github/directory-file-count](https://shields.io/github/directory-file-count/Freed-Wu/fzf-tab-source)
Expand All @@ -27,25 +27,51 @@
![github/v](https://shields.io/github/v/release/Freed-Wu/fzf-tab-source)

This zsh plugin is a collection of
<https://github.com/Aloxaf/fzf-tab/wiki/Preview>. Please read the wiki first.
[fzf-tab](https://github.com/Aloxaf/fzf-tab)'s sources. Please read
[the wiki](https://github.com/Aloxaf/fzf-tab/wiki/Preview) first.

## Install

This plugin respects
[zsh plugin standard](https://github.com/zdharma-continuum/Zsh-100-Commits-Club/blob/master/Zsh-Plugin-Standard.adoc),
so if you use any plugin manager and follow the instructions of your plugin
manager, it can be installed correctly.

If you don't use any plugin manager, just add the following code to `~/.zshrc`:

```zsh
source /the/directory/of/this/plugin/*.plugin.zsh
```

## Customize

You can use your customized fzf-tab sources to override the default, such as:

```zsh
zstyle ':fzf-tab:sources' config-directory /the/directory/containing/your/source.zsh
```

**NOTE: You need to install [lesspipe](https://github.com/wofr06/lesspipe) to
preview directory, text, image, etc better.**
## Optional Dependencies

- [some programs](functions/helper.zsh).
- [lesspipe](https://github.com/wofr06/lesspipe): preview directory, text,
image, etc better. You need to write your `~/.lessfilter` to customize
`lesspipe`. My
[~/.lessfilter](https://github.com/Freed-Wu/my-dotfiles/blob/main/.lessfilter)
can be a reference.
- [gitmoji-cli](https://github.com/carloscuesta/gitmoji-cli): `gitmoji -u` to
download `~/.gitmoji`
- [pinyin-completion](https://github.com/petronny/pinyin-completion): complete
pinyin in your zsh.

## Preview

![dir](https://user-images.githubusercontent.com/32936898/195973421-24f28667-3754-46f2-9dd4-42523285aec2.png)

![text](https://user-images.githubusercontent.com/32936898/195970444-4220411d-5a11-4b60-a19f-a8839d827711.png)

![image](https://user-images.githubusercontent.com/32936898/195970442-1ca8db87-fcb2-469e-8578-163ea73a19ff.png)

**NOTE: You need to install [pinyin-completion](https://github.com/petronny/pinyin-completion).**

![user-expand](https://user-images.githubusercontent.com/32936898/195970438-1282c11b-c2e4-455e-8a6a-76c7446ecf8b.png)

![-parameter-](https://user-images.githubusercontent.com/32936898/195970440-98a83556-e664-42e6-9adb-918b865053f3.png)
Expand Down
8 changes: 5 additions & 3 deletions functions/helper.zsh
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
# define some functions to avoid any error that these programs don't exist
(($+commands[bat])) || bat() {cat}
(($+commands[pygmentize])) || pygmentize() {cat}
(($+commands[delta])) || delta() {cat}
(($+commands[less])) || less() {ls -l}
(($+commands[finger])) || finger() {(($+commands[pinky])) && pinky $@ || whoami}
(($+commands[pandoc])) || pandoc() {cat ${@[-1]}}
(($+commands[grc])) || grc() {eval ${@[2,-1]}}

# dictionary $ZINIT cannot be passed
PLUGINS_DIR=${ZINIT[PLUGINS_DIR]}
(($+commands[jq])) || jq() {echo ';'}

mkdir -p ~/.gitmoji
touch ~/.gitmoji/gitmojis.json

# dictionary $ZINIT cannot be passed
PLUGINS_DIR=${ZINIT[PLUGINS_DIR]}
24 changes: 12 additions & 12 deletions sources/-command-.zsh
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# :fzf-tab:complete:(-command-:|command:option-(v|V)-rest)
case $group in
'external command')
less =$word
;;
'executable file')
less ${realpath#--*=}
;;
'builtin command')
run-help $word | bat --color=always -plman
;;
parameter)
echo ${(P)word}
;;
'external command')
less =$word
;;
'executable file')
less ${realpath#--*=}
;;
'builtin command')
run-help $word | bat --color=always -plman
;;
parameter)
echo ${(P)word}
;;
esac
14 changes: 7 additions & 7 deletions sources/adb.zsh
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# :fzf-tab:complete:(\\|*/|)adb-(push|pull|shell):argument-rest
case $group in
'file/folder on device')
# https://github.com/Aloxaf/fzf-tab/issues/325
adb shell 'type=$(file -L '"$ctxt[hpre]$word"' | cut -d: -f2) && test -z "${type/ASCII text/}" && cat '"$ctxt[hpre]$word"' || ls -l --color '$ctxt[hpre]$word
;;
'local file/folder')
less $realpath
;;
'file/folder on device')
# https://github.com/Aloxaf/fzf-tab/issues/325
adb shell 'type=$(file -L '"$ctxt[hpre]$word"' | cut -d: -f2) && test -z "${type/ASCII text/}" && cat '"$ctxt[hpre]$word"' || ls -l --color '$ctxt[hpre]$word
;;
'local file/folder')
less $realpath
;;
esac
12 changes: 6 additions & 6 deletions sources/bat.zsh
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# :fzf-tab:complete:(\\|*/|)bat:argument-rest
case $group in
subcommand)
bat cache --help | bat --color=always -plhelp
;;
*)
[[ -f ${realpath#--*=} ]] && bat ${realpath#--*=} || less ${realpath#--*=}
;;
subcommand)
bat cache --help | bat --color=always -plhelp
;;
*)
[[ -f ${realpath#--*=} ]] && bat ${realpath#--*=} || less ${realpath#--*=}
;;
esac
6 changes: 3 additions & 3 deletions sources/bindkey.zsh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# :fzf-tab:complete:(\\|)bindkey:option-M-1
case $group in
keymap)
bindkey -M$word | bat --color=always -pltsv
;;
keymap)
bindkey -M$word | bat --color=always -pltsv
;;
esac
6 changes: 3 additions & 3 deletions sources/cowsay.zsh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# :fzf-tab:complete:(\\|*/|)cowsay:
case $group in
'cow file')
cowsay -f $word hello
;;
'cow file')
cowsay -f $word hello
;;
esac
12 changes: 6 additions & 6 deletions sources/dpkg.zsh
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# :fzf-tab:complete:(\\|*/|)dpkg:argument-rest
case $group in
file)
dpkg -S $word
;;
package)
dpkg -L $word
;;
file)
dpkg -S $word
;;
package)
dpkg -L $word
;;
esac
6 changes: 3 additions & 3 deletions sources/flatpak.zsh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# :fzf-tab:complete:(\\|*/|)flatpak:
case $group in
argument)
flatpak $word --help | bat --color=always -plhelp
;;
argument)
flatpak $word --help | bat --color=always -plhelp
;;
esac
2 changes: 1 addition & 1 deletion sources/gdu.zsh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# :fzf-tab:complete:(\\|*/|)gdu:argument-rest
[ -d $realpath ] && gdu -n $realpath || grc --colour=on du -sh $realpath
[ -d $realpath ] && gdu -n $realpath || grc --colour=on du -sh $realpath
4 changes: 2 additions & 2 deletions sources/gio.zsh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# :fzf-tab:complete:(\\|*/|)gio:
[[ -f $realpath ]] && less $realpath \
|| gio help $word 2>&1 | bat --color=always -plhelp
[[ -f $realpath ]] && less $realpath ||
gio help $word 2>&1 | bat --color=always -plhelp
6 changes: 3 additions & 3 deletions sources/git-blame.zsh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# :fzf-tab:complete:git-blame:argument-2
case $group in
'cached file')
git blame $word | delta
;;
'cached file')
git blame $word | delta
;;
esac
21 changes: 12 additions & 9 deletions sources/git-checkout.zsh
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# :fzf-tab:complete:git-checkout:argument-rest
case $group in
'modified file')
git diff $word | delta
;;
'recent commit object name')
git log --color=always $word | perl -pe$(jq -j '.[] as $i | "s=" + $i.code + "=" + $i.emoji + "=g;"' ~/.gitmoji/gitmojis.json) | delta
;;
*)
git log --color=always $word | perl -pe$(jq -j '.[] as $i | "s=" + $i.code + "=" + $i.emoji + "=g;"' ~/.gitmoji/gitmojis.json)
;;
'modified file')
git diff $word | delta
;;
'recent commit object name')
git log --color=always $word |
perl -pe$(jq -j '.[] | "s=\(.code)=\(.emoji)=g;"' ~/.gitmoji/gitmojis.json) |
delta
;;
*)
git log --color=always $word |
perl -pe$(jq -j '.[] | "s=\(.code)=\(.emoji)=g;"' ~/.gitmoji/gitmojis.json)
;;
esac
12 changes: 6 additions & 6 deletions sources/git-diff.zsh
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# :fzf-tab:complete:git-(diff|cherry-pick):argument-rest
case $group in
'tree file')
less ${realpath#--*=}
;;
*)
git diff $word | delta
;;
'tree file')
less ${realpath#--*=}
;;
*)
git diff $word | delta
;;
esac
3 changes: 2 additions & 1 deletion sources/git-log.zsh
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# :fzf-tab:complete:git-log:argument-1
git log --color=always $word | perl -pe$(jq -j '.[] as $i | "s=" + $i.code + "=" + $i.emoji + "=g;"' ~/.gitmoji/gitmojis.json)
git log --color=always $word |
perl -pe$(jq -j '.[] | "s=\(.code)=\(.emoji)=g;"' ~/.gitmoji/gitmojis.json)
18 changes: 9 additions & 9 deletions sources/git-push.zsh
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# :fzf-tab:complete:git-((push|pull):argument-1|fetch:argument-rest)
case $group in
'local repository')
less ${realpath#--*=}
;;
remote)
git remote show $word
;;
*host*)
grc --colour=on ping -c1 $word
;;
'local repository')
less ${realpath#--*=}
;;
remote)
git remote show $word
;;
*host*)
grc --colour=on ping -c1 $word
;;
esac
14 changes: 8 additions & 6 deletions sources/git-reflog.zsh
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# :fzf-tab:complete:git-reflog(|-*):argument-1
case $group in
command)
git reflog --color=always show | perl -pe$(jq -j '.[] as $i | "s=" + $i.code + "=" + $i.emoji + "=g;"' ~/.gitmoji/gitmojis.json)
;;
reference)
git reflog --color=always $word | perl -pe$(jq -j '.[] as $i | "s=" + $i.code + "=" + $i.emoji + "=g;"' ~/.gitmoji/gitmojis.json)
;;
command)
git reflog --color=always show |
perl -pe$(jq -j '.[] | "s=\(.code)=\(.emoji)=g;"' ~/.gitmoji/gitmojis.json)
;;
reference)
git reflog --color=always $word |
perl -pe$(jq -j '.[] | "s=\(.code)=\(.emoji)=g;"' ~/.gitmoji/gitmojis.json)
;;
esac
12 changes: 6 additions & 6 deletions sources/git-show.zsh
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# :fzf-tab:complete:git-show:argument-rest
case $group in
'commit tag')
git show --color=always $word
;;
*)
git show --color=always $word | delta
;;
'commit tag')
git show --color=always $word
;;
*)
git show --color=always $word | delta
;;
esac
4 changes: 2 additions & 2 deletions sources/groff.zsh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# :fzf-tab:complete:(\\|*/|)groff:argument-1
[[ -f $realpath ]] && groff $realpath | pygmentize -l postscript \
|| less $realpath
[[ -f $realpath ]] && groff $realpath | pygmentize -l postscript ||
less $realpath
6 changes: 3 additions & 3 deletions sources/has.zsh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# :fzf-tab:complete:(\\|*/|)has:argument-rest
case $group in
'external command')
has $word
;;
'external command')
has $word
;;
esac
6 changes: 3 additions & 3 deletions sources/help2man.zsh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# :fzf-tab:complete:(\\|*/|)help2man:
[[ -f $realpath ]] \
&& help2man $realpath | man --local-file - | bat --color=always -plman \
|| less $realpath
[[ -f $realpath ]] &&
help2man $realpath | man --local-file - | bat --color=always -plman ||
less $realpath
6 changes: 3 additions & 3 deletions sources/ip.zsh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# :fzf-tab:complete:(\\|*/|)ip:
case $group in
'ip command')
ip $word help 2>&1 | bat --color=always -plhelp
;;
'ip command')
ip $word help 2>&1 | bat --color=always -plhelp
;;
esac
Loading

0 comments on commit cffe29e

Please sign in to comment.