diff options
| author | Junegunn Choi <junegunn.c@gmail.com> | 2025-01-09 17:00:21 +0900 |
|---|---|---|
| committer | Junegunn Choi <junegunn.c@gmail.com> | 2025-01-09 17:00:46 +0900 |
| commit | 55e3c73221e1f6e4c48f2c3f7517befc7d0945cf (patch) | |
| tree | eafe7885c633b90cfaf513f7b07a69224d89abd7 /bin | |
| parent | 6783417504a2e2a378b8a55a5dd111c18a051425 (diff) | |
| download | fzf-55e3c73221e1f6e4c48f2c3f7517befc7d0945cf.tar.gz | |
fzf-preview.sh: Support FILEPATH:LINE[:COL] argument
Diffstat (limited to 'bin')
| -rwxr-xr-x | bin/fzf-preview.sh | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/bin/fzf-preview.sh b/bin/fzf-preview.sh index ecec41ae..e74e46e2 100755 --- a/bin/fzf-preview.sh +++ b/bin/fzf-preview.sh @@ -9,11 +9,23 @@ # - https://iterm2.com/utilities/imgcat if [[ $# -ne 1 ]]; then - >&2 echo "usage: $0 FILENAME" + >&2 echo "usage: $0 FILENAME[:LINENO][:IGNORED]" exit 1 fi file=${1/#\~\//$HOME/} + +center=0 +if [[ ! -r $file ]]; then + if [[ $file =~ ^(.+):([0-9]+)\ *$ ]] && [[ -r ${BASH_REMATCH[1]} ]]; then + file=${BASH_REMATCH[1]} + center=${BASH_REMATCH[2]} + elif [[ $file =~ ^(.+):([0-9]+):[0-9]+\ *$ ]] && [[ -r ${BASH_REMATCH[1]} ]]; then + file=${BASH_REMATCH[1]} + center=${BASH_REMATCH[2]} + fi +fi + type=$(file --brief --dereference --mime -- "$file") if [[ ! $type =~ image/ ]]; then @@ -32,7 +44,7 @@ if [[ ! $type =~ image/ ]]; then exit fi - ${batname} --style="${BAT_STYLE:-numbers}" --color=always --pager=never -- "$file" + ${batname} --style="${BAT_STYLE:-numbers}" --color=always --pager=never --highlight-line="${center:-0}" -- "$file" exit fi |
