diff --git a/fff b/fff index 9b99625..50f676f 100755 --- a/fff +++ b/fff @@ -102,6 +102,17 @@ get_ls_colors() { source /dev/stdin <<< "$ls_exts" >/dev/null 2>&1 } +cd_file() { + # Handle CD on exit based on the user's preference. + if [[ $FFF_CD_FILE == stdout ]]; then + printf '%s\n' "$PWD" + + else + : "${FFF_CD_FILE:=${XDG_CACHE_HOME:=${HOME}/.cache}/fff/.fff_d}" + printf '%s\n' "$PWD" > "$FFF_CD_FILE" + fi +} + status_line() { # Status_line to print when files are marked for operation. local mark_ui="[${#marked_files[@]}] selected (${file_program[*]}) [p] ->" @@ -669,8 +680,6 @@ key() { # Don't allow user to redefine 'q' so a bad keybinding doesn't # remove the option to quit. q) - : "${FFF_CD_FILE:=${XDG_CACHE_HOME:=${HOME}/.cache}/fff/.fff_d}" - printf '%s\n' "$PWD" > "$FFF_CD_FILE" exit ;; esac @@ -722,7 +731,7 @@ main() { # Trap the exit signal (we need to reset the terminal to a useable state.) # '\e[?1049l': Restore saved terminal screen. - trap 'reset_terminal; printf "\e[?1049l"' EXIT + trap 'reset_terminal; printf "\e[?1049l"; cd_file' EXIT # Trap 'Ctrl+c' and exit by mimicking the 'q' keypress. # This allow us to run the same plumbing on exit for both.