#!/bin/bash
D_CONF="-fn "-xos4-terminus-medium-r-normal--12-120-72-72-c-60-*-*" -nb "#cccccc" -nf "#111111" -sb "#111111" -sf "#cccccc""
DMENU="dmenu ${D_CONF}"
H_FILE="$HOME/.config/dfm.last"
function is_type {
if file --mime "$1" | grep "$2" &> /dev/null
then
return 0
fi
return 1
}
function cd_dir {
cd "$1"
echo "`pwd`" > "$H_FILE"
}
function open_file {
eval "${1} \"${2}\" &> /dev/null"
}
if [ -e "$H_FILE" ]; then
y_n=`echo -e "Yes\nNo" | $DMENU -p "Open last dir?"`
if [ "$y_n" = "Yes" ]; then
cd_dir "`cat "$H_FILE"`"
var=`ls`
else
var=`ls`
fi
else
var=`ls`
fi
while [ true ]; do
if [ "$var" ]; then
var=`echo -e "../\n$var" | $DMENU -p "dfm"`
else
var=`echo "../" | $DMENU -p "dfm"`
fi
if [ -d "$var" ]; then
cd_dir "$var"
elif is_type "$var" "image/*"
then
open_file "feh" "$var"
elif is_type "$var" "video/*"
then
open_file "mplayer" "$var"
elif is_type "$var" "text/*"
then
open_file "urxvt -e emacs -nw" "$var"
else
exit 0
fi
var=`ls`
done