Skip to content
Myr

[shell] Replace `sed` with `-mindepth 1` and `cut` (#844)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Pierre Neidhardt · committed by Junegunn Choi · parent 21da02f · Browse files · 3 files+8 added−9 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+8 added−9 removed

  • other:+8 added−9 removed

3 files+8 added−9 removed

modified:shell/key-bindings.bash+2 added-2 removed
modified:shell/key-bindings.fish+4 added-4 removed
1# Key bindings2# ------------3function fzf_key_bindings45 # Store last token in $dir as root for the 'find' command5 # Store current token in $dir as root for the 'find' command6 function fzf-file-widget -d "List files and folders"7 set -l dir (commandline -t)8 # The commandline token might be escaped, we need to unescape it.9 set dir (eval "printf '%s' $dir")
8 unmodified lines
18 set -q FZF_CTRL_T_COMMAND; or set -l FZF_CTRL_T_COMMAND "19 command find -L \$dir -mindepth 1 \\( -path \$dir'*/\\.*' -o -fstype 'devfs' -o -fstype 'devtmpfs' \\) -prune \20 -o -type f -print \21 -o -type d -print \22 -o -type l -print 2> /dev/null | sed 's#^\./##'"22 -o -type l -print 2> /dev/null | cut -b3-"2324 set -q FZF_TMUX_HEIGHT; or set FZF_TMUX_HEIGHT 40%25 begin26 set -lx FZF_DEFAULT_OPTS "--height $FZF_TMUX_HEIGHT --reverse $FZF_DEFAULT_OPTS $FZF_CTRL_T_OPTS"
26 unmodified lines
53 end5455 function fzf-cd-widget -d "Change directory"56 set -q FZF_ALT_C_COMMAND; or set -l FZF_ALT_C_COMMAND "57 command find -L . \\( -path '*/\\.*' -o -fstype 'devfs' -o -fstype 'devtmpfs' \\) -prune \58 -o -type d -print 2> /dev/null | sed 1d | cut -b3-"57 command find -L . -mindepth 1 \\( -path '*/\\.*' -o -fstype 'devfs' -o -fstype 'devtmpfs' \\) -prune \58 -o -type d -print 2> /dev/null | cut -b3-"59 set -q FZF_TMUX_HEIGHT; or set FZF_TMUX_HEIGHT 40%60 begin61 set -lx FZF_DEFAULT_OPTS "--height $FZF_TMUX_HEIGHT --reverse $FZF_DEFAULT_OPTS $FZF_ALT_C_OPTS"62 eval "$FZF_ALT_C_COMMAND | "(__fzfcmd)" +m" | read -l result
25 unmodified lines
modified:shell/key-bindings.zsh+2 added-3 removed
36 unmodified lines
37bindkey '^T' fzf-file-widget3839# ALT-C - cd into the selected directory40fzf-cd-widget() {41 local cmd="${FZF_ALT_C_COMMAND:-"command find -L . \\( -path '*/\\.*' -o -fstype 'devfs' -o -fstype 'devtmpfs' -o -fstype 'proc' \\) -prune \42 -o -type d -print 2> /dev/null | sed 1d | cut -b3-"}"41 local cmd="${FZF_ALT_C_COMMAND:-"command find -L . -mindepth 1 \\( -path '*/\\.*' -o -fstype 'devfs' -o -fstype 'devtmpfs' -o -fstype 'proc' \\) -prune \42 -o -type d -print 2> /dev/null | cut -b3-"}"43 setopt localoptions pipefail 2> /dev/null44 local dir="$(eval "$cmd" | FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} --reverse $FZF_DEFAULT_OPTS $FZF_ALT_C_OPTS" $(__fzfcmd) +m)"45 if [[ -z "$dir" ]]; then46 zle redisplay
28 unmodified lines
75zle -N fzf-history-widget76bindkey '^R' fzf-history-widget7778fi79