mirror of
https://github.com/wfxr/forgit.git
synced 2026-09-10 07:16:23 -04:00
feat: add FORGIT_IGNORE_PAGER option (#112)
* added FORGIT_BAT_OPTION to add optional options to bat * fixed arguments * removed curly brace in for fish * BAT_OPTION to BAT_OPTS * BAT_OPTION to BAT_OPTS in readme * changed BAT_OPTS TO BAT_PAGER which is directly the command used to output * update readme for FORGIT_IGNORE_PAGER
This commit is contained in:
parent
e8f32648a6
commit
d8d530ec50
|
|
@ -136,6 +136,14 @@ FORGIT_FZF_DEFAULT_OPTS="
|
|||
"
|
||||
```
|
||||
|
||||
You can forgit gitignore pager with `FORGIT_IGNORE_PAGER`.
|
||||
default option is `FORGIT_IGNORE_PAGER="bat -l gitignore --color=always"`
|
||||
|
||||
``` bash
|
||||
# this is a example. see bat --help
|
||||
FORGIT_IGNORE_PAGER='bat -l gitignore -pp --color=always --theme="Monokai Extended Origin"'
|
||||
```
|
||||
|
||||
Customizing fzf options for each command individually is also supported:
|
||||
|
||||
| Command | Option |
|
||||
|
|
|
|||
|
|
@ -238,13 +238,17 @@ if test -z "$FORGIT_GI_TEMPLATES"
|
|||
set -x FORGIT_GI_TEMPLATES $FORGIT_GI_REPO_LOCAL/templates
|
||||
end
|
||||
|
||||
if test -z "FORGIT_IGNORE_PAGER"
|
||||
set -x FORGIT_IGNORE_PAGER bat -l gitignore --color=always
|
||||
end
|
||||
|
||||
function forgit::ignore
|
||||
if not test -d "$FORGIT_GI_REPO_LOCAL"
|
||||
forgit::ignore::update
|
||||
end
|
||||
|
||||
# https://github.com/sharkdp/bat.git
|
||||
type -q bat > /dev/null 2>&1 && set cat 'bat -l gitignore --color=always' || set cat "cat"
|
||||
type -q bat > /dev/null 2>&1 && set cat $FORGIT_IGNORE_PAGER || set cat "cat"
|
||||
set cmd "$cat $FORGIT_GI_TEMPLATES/{2}{,.gitignore} 2>/dev/null"
|
||||
set opts "
|
||||
$FORGIT_FZF_DEFAULT_OPTS
|
||||
|
|
@ -264,7 +268,7 @@ function forgit::ignore
|
|||
end
|
||||
|
||||
if type -q bat > /dev/null 2>&1
|
||||
forgit::ignore::get $args | bat -l gitignore
|
||||
forgit::ignore::get $args | $FORGIT_IGNORE_PAGER
|
||||
else
|
||||
forgit::ignore::get $args
|
||||
end
|
||||
|
|
|
|||
|
|
@ -166,12 +166,13 @@ forgit::cherry::pick() {
|
|||
export FORGIT_GI_REPO_REMOTE=${FORGIT_GI_REPO_REMOTE:-https://github.com/dvcs/gitignore}
|
||||
export FORGIT_GI_REPO_LOCAL="${FORGIT_GI_REPO_LOCAL:-${XDG_CACHE_HOME:-~/}}/.forgit/gi/repos/dvcs/gitignore"
|
||||
export FORGIT_GI_TEMPLATES=${FORGIT_GI_TEMPLATES:-$FORGIT_GI_REPO_LOCAL/templates}
|
||||
export FORGIT_IGNORE_PAGER=${FORGIT_IGNORE_PAGER:-bat -l gitignore --color=always}
|
||||
|
||||
forgit::ignore() {
|
||||
[ -d "$FORGIT_GI_REPO_LOCAL" ] || forgit::ignore::update
|
||||
local IFS cmd args cat opts
|
||||
# https://github.com/sharkdp/bat.git
|
||||
hash bat &>/dev/null && cat='bat -l gitignore --color=always' || cat="cat"
|
||||
hash bat &>/dev/null && cat="${FORGIT_IGNORE_PAGER}" || cat="cat"
|
||||
cmd="$cat $FORGIT_GI_TEMPLATES/{2}{,.gitignore} 2>/dev/null"
|
||||
opts="
|
||||
$FORGIT_FZF_DEFAULT_OPTS
|
||||
|
|
@ -180,11 +181,11 @@ forgit::ignore() {
|
|||
"
|
||||
# shellcheck disable=SC2206,2207
|
||||
IFS=$'\n' args=($@) && [[ $# -eq 0 ]] && args=($(forgit::ignore::list | nl -nrn -w4 -s' ' |
|
||||
FZF_DEFAULT_OPTS="$opts" fzf --preview="$cmd" |awk '{print $2}'))
|
||||
FZF_DEFAULT_OPTS="$opts" fzf --preview="eval $cmd" | awk '{print $2}'))
|
||||
[ ${#args[@]} -eq 0 ] && return 1
|
||||
# shellcheck disable=SC2068
|
||||
if hash bat &>/dev/null; then
|
||||
forgit::ignore::get ${args[@]} | bat -l gitignore
|
||||
forgit::ignore::get ${args[@]} | eval "${FORGIT_IGNORE_PAGER}"
|
||||
else
|
||||
forgit::ignore::get ${args[@]}
|
||||
fi
|
||||
|
|
|
|||
Loading…
Reference in a new issue