diff options
author | Dylan Araps <dylan.araps@gmail.com> | 2019-01-15 23:21:51 +0200 |
---|---|---|
committer | Dylan Araps <dylan.araps@gmail.com> | 2019-01-15 23:21:51 +0200 |
commit | ce390e8af6cecae51f5c4d1c246ef9d9b640e18c (patch) | |
tree | 8d3a7285a4dddb5be963d1a5c8836cf6c59e7dd7 | |
parent | 4f1e9064b6607785fea94a722cee12f5fdc1f351 (diff) |
general: use FFF_CD_FILE=stdout to print dir on exitcd_stdout
-rwxr-xr-x | fff | 15 |
1 files changed, 12 insertions, 3 deletions
@@ -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. |