#!/bin/bash

mark="$@"
if [ -z "$mark" ]; then
    sleep 0.3
    xdotool key F11; sleep 0.1; xdotool type "pwd > /tmp/pwd"; xdotool key Return
    sleep 0.5
    mark=$(cat /tmp/pwd)
    rm /tmp/pwd
fi

h_file="$HOME/.config/rox.sourceforge.net/ROX-Filer/marked-directories.lst"
IFS=$'\n'
marked=($(cat $h_file))
mv $h_file $h_file.bak
labels=(${marked[@]#*‖})
label="$(basename "$mark")"
n=$(echo ${labels[@]} | grep -o $label | tr [:space:] \\n | grep -o $label | wc -l)
if [ $n -gt 0 ]; then ((n++1)); else n=""; fi
if [ -n "$n" ]; then label="$label $n"; fi
mark="$mark‖$label"
marked=(${marked[@]} "$mark")

echo "${marked[*]}" > $h_file

