From 448ef4cb5a47479632ae441fdee2a549a281cffa Mon Sep 17 00:00:00 2001 From: Roy-Orbison Date: Fri, 5 Aug 2022 13:40:30 +0930 Subject: [PATCH] Enable cd on exit by sourcing the main script --- README.md | 5 +++++ fff | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/README.md b/README.md index a17e4a4..40ba1af 100644 --- a/README.md +++ b/README.md @@ -92,6 +92,11 @@ A simple file manager written in `bash`. **NOTE:** `fff` can be uninstalled easily using `make uninstall`. This removes all of files from your system. ### CD on Exit +#### Bash +```sh +# Add this to your .bashrc or equivalent. +. fff +``` #### Bash and Zsh ```sh # Add this to your .bashrc, .zshrc or equivalent. diff --git a/fff b/fff index 16766e3..107770e 100755 --- a/fff +++ b/fff @@ -2,6 +2,16 @@ # # fff - fucking fast file-manager. +# Enable cd on exit by sourcing fff +if (return 0 2>/dev/null); then + function fff { + command fff "$@" + [[ ${FFF_CD_ON_EXIT:-1} == 1 ]] && + cd "$(cat "${XDG_CACHE_HOME:-${HOME}/.cache}/fff/.fff_d")" + } + return +fi + get_os() { # Figure out the current operating system to set some specific variables. # '$OSTYPE' typically stores the name of the OS kernel.