summaryrefslogtreecommitdiffstats
path: root/Examples/rofi-file-browser.sh
blob: ace91c79ddb53c744d1e944128f06cf3c78c6901 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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