From 04e1cdc7c87ae0d97f7c6983cffa3b5bc3eead3d Mon Sep 17 00:00:00 2001 From: Gardouille Date: Tue, 8 Jan 2019 14:13:54 +0100 Subject: [PATCH] Add some fzf commands to opend pdf files Also define a PDF_VIEWER var for a default PDF tool. --- zshenv | 7 +++++++ zshrc | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 58 insertions(+), 1 deletion(-) diff --git a/zshenv b/zshenv index 04e9f00..7140430 100644 --- a/zshenv +++ b/zshenv @@ -57,6 +57,13 @@ export LESS_TERMCAP_ue=$'\E[0m' # fin DIRSTACKSIZE=10 export DIRSTACKSIZE +# Default PDF viewer +if [ $(command -v zathura) ]; then + PDF_VIEWER="zathura" +else + PDF_VIEWER="evince" +fi + # Permissions rw-r--r-- pour les fichiers crées # et rwxr-xr-x pour les répertoires crées umask 022 diff --git a/zshrc b/zshrc index ffeb04b..461e6dc 100644 --- a/zshrc +++ b/zshrc @@ -368,7 +368,6 @@ alias -s gif='mirage ' alias -s mp4='smplayer ' alias -s avi='smplayer ' alias -s flv='smplayer ' -alias -s pdf='evince ' alias -s log='tail -f' alias -s conf='vim ' alias -s gz='gunzip ' @@ -1253,6 +1252,57 @@ v() { fi } +# pdf - fuzzy open with "${PDF_VIEWER}" from current directory +# cd into the directory of the selected file +# open the selected file with "${PDF_VIEWER}" +pdf() { + local files + + files=$(find ${1:-.} -iname "*.pdf" 2> /dev/null | fzf +m) && + + if [[ -n $files ]] + then + dir=$(dirname "${files}") + cd "${dir}" + file=$(basename "${files}") + "${PDF_VIEWER}" -- "${file}" + fi +} + +# pdfe - fuzzy open with evince from current directory +# cd into the directory of the selected file +# open the selected file with evince +pdfe() { + local files + + files=$(find ${1:-.} -iname "*.pdf" 2> /dev/null | fzf +m) && + + if [[ -n $files ]] + then + dir=$(dirname "${files}") + cd "${dir}" + file=$(basename "${files}") + evince -- "${file}" + fi +} + +# pdfz - fuzzy open with zathura from current directory +# cd into the directory of the selected file +# open the selected file with zathura +pdfz() { + local files + + files=$(find ${1:-.} -iname "*.pdf" 2> /dev/null | fzf +m) && + + if [[ -n $files ]] + then + dir=$(dirname "${files}") + cd "${dir}" + file=$(basename "${files}") + zathura -- "${file}" + fi +} + # zsh-syntax-highlighting {{{ ## Activate if plugin is available [ -f ~/repos/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh ] && source ~/repos/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh