diff options
| author | Loek Le Blansch <loek@pipeframe.xyz> | 2025-03-05 19:33:01 +0100 | 
|---|---|---|
| committer | Loek Le Blansch <loek@pipeframe.xyz> | 2025-03-05 19:33:01 +0100 | 
| commit | ee68f66734f490a998eb169ee6208e919182a7dd (patch) | |
| tree | b4e8bcfa69753c6e1fc37cc4ef92bd9aebcfcd22 | |
| parent | 216127ffdcff2b41183a1d0137edb850abd09c38 (diff) | |
add set-default script
| -rwxr-xr-x | .local/share/bin/set-default | 32 | 
1 files changed, 32 insertions, 0 deletions
| diff --git a/.local/share/bin/set-default b/.local/share/bin/set-default new file mode 100755 index 0000000..d93f65c --- /dev/null +++ b/.local/share/bin/set-default @@ -0,0 +1,32 @@ +#!/bin/sh +SCRIPT_NAME="$(basename "$0")" + +usage() { +	code=0 +	if [ -z "$1" ] ; then +	cat << EOF +Set desktop entry ENTRY as default application for opening files with the same +type as FILE + +EOF +	else +		echo "error: $1" >&2 +		code=1 +	fi +	cat << EOF +usage: +	$SCRIPT_NAME ENTRY FILE [FILE] +EOF +	exit $code +} + +[ $# -eq 0 ] && usage +DESKTOP_ENTRY="$1"; shift +[ -z "$DESKTOP_ENTRY" ] && usage "no desktop entry" +[ $# -lt 1 ] && usage "no reference file(s)" + +for file in "$@" ; do +	mimetype="$(xdg-mime query filetype "$file")" +	xdg-mime default "$DESKTOP_ENTRY" "$mimetype" +done + |