#!/usr/bin/env bash ## Copyright (C) 2020-2024 Aditya Shakya ## ## Openbox Pipemenu to parse .recently-used.xbel and generate openbox pipe menu maximum_entries=15 ####################################################################### # look for recently-used.xbel if [ "$XDG_DATA_HOME" ] && [ -r "${XDG_DATA_HOME}/recently-used.xbel" ]; then file_path="${XDG_DATA_HOME}/recently-used.xbel" elif [ -r "${HOME}/.local/share/recently-used.xbel" ]; then file_path="${HOME}/.local/share/recently-used.xbel" elif [ -r "${HOME}/.recently-used.xbel" ]; then file_path="${HOME}/.recently-used.xbel" else echo "$0: cannot find a readable recently-used.xbel file" >&2 echo ' ' exit 1 fi # if argument is --clear, empty .recently-used.xbel [[ "$1" == '--clear' ]] && { cat <<':EOF' > "${file_path}" :EOF exit } maximum_entries=$((maximum_entries+2)) pre=' ' post=' ' files=$(tac "${file_path}" | awk -v MAX="$maximum_entries" -v PR="$pre" -v MI="$mid" -v PO="$post" 'BEGIN { RS=""; FS=""; } (NR == MAX) {exit} !/ ''"$0"'' --clear ' printf '%s' "$output" # printf because echo sometimes eats backslashes