diff options
author | Dave Davenport <qball@gmpclient.org> | 2015-01-28 07:49:52 +0100 |
---|---|---|
committer | Dave Davenport <qball@gmpclient.org> | 2015-01-28 07:49:52 +0100 |
commit | 836036574be4408508ae88be4ac8e5524e23e6e8 (patch) | |
tree | 0d833f623e38df0449a785354e5566fc73b81e4d /Examples | |
parent | 7c81152ca5239e3c13976ad27428ae159afd6f87 (diff) |
Add file browser example.
-switchers "file:rofi-file-browser.sh" -show file
Diffstat (limited to 'Examples')
-rwxr-xr-x | Examples/rofi-file-browser.sh | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/Examples/rofi-file-browser.sh b/Examples/rofi-file-browser.sh new file mode 100755 index 00000000..ace91c79 --- /dev/null +++ b/Examples/rofi-file-browser.sh @@ -0,0 +1,46 @@ +#!/usr/bin/env bash + +EDITOR=xdg-open + +CUR_DIR=$PWD + +PREV_LOC_FILE=~/.rofi_fb_prevloc + +# Read last location, otherwise we default to PWD. +if [ -f "${PREV_LOC_FILE}" ] +then + CUR_DIR=$(cat "${PREV_LOC_FILE}") +fi + +# Handle argument. +if [ -n "$@" ] +then + CUR_DIR="${CUR_DIR}/$@" +fi + +# If argument is no directory. +if [ ! -d "${CUR_DIR}" ] +then + if [ -x "${CUR_DIR}" ] + then + coproc ( "${CUR_DIR}" & > /dev/null 2>&1 ) + exec 1>&- + exit; + elif [ -f "${CUR_DIR}" ] + then + coproc ( ${EDITOR} "${CUR_DIR}" & > /dev/null 2>&1 ) + exit; + fi + exit; +fi + +# process current dir. +if [ -n "${CUR_DIR}" ] +then + CUR_DIR=$(readlink -e "${CUR_DIR}") + echo "${CUR_DIR}" > "${PREV_LOC_FILE}" + pushd "${CUR_DIR}" >/dev/null +fi + +echo ".." +ls |