#!/usr/bin/env bash

dir=$(dirname "$1")
base=$(basename "$1")

if [ "$base" == "" ]; then
	exit 3
fi

export LESSHISTFILE="$dir/.$base.hst"
touch $LESSHISTFILE || :

# use a fallback dir if it's not writable
if [ ! -w "$LESSHISTFILE" ]
then
    dir="$HOME/var/marks"
    mkdir -p "$dir"
    export LESSHISTFILE="$dir/.$base.hst"
fi

# export LESS="-cix8JRM --save-marks"
less "+''" --save-marks "$@"