75 lines
2.1 KiB
Bash
Executable File
75 lines
2.1 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
# This file is part of I38.
|
|
#
|
|
# I38 is free software: you can redistribute it and/or modify it under the terms
|
|
# of the GNU General Public License as published by the Free Software
|
|
# Foundation, either version 3 of the License, or (at your option) any later
|
|
# version.
|
|
|
|
set -u
|
|
|
|
set_ini_key() {
|
|
local filePath="$1"
|
|
local sectionName="$2"
|
|
local keyName="$3"
|
|
local keyValue="$4"
|
|
local tempFile
|
|
|
|
mkdir -p -- "$(dirname -- "$filePath")" || return 0
|
|
touch -- "$filePath" || return 0
|
|
tempFile="$(mktemp "${filePath}.tmp.XXXXXX")" || return 0
|
|
|
|
awk -v section="$sectionName" -v key="$keyName" -v value="$keyValue" '
|
|
BEGIN {
|
|
inSection = 0
|
|
sawSection = 0
|
|
wroteKey = 0
|
|
}
|
|
$0 ~ "^\\[" {
|
|
if (inSection && !wroteKey) {
|
|
print key "=" value
|
|
wroteKey = 1
|
|
}
|
|
inSection = ($0 == "[" section "]")
|
|
if (inSection) {
|
|
sawSection = 1
|
|
}
|
|
}
|
|
inSection && $0 ~ "^[[:space:]]*" key "[[:space:]]*=" {
|
|
if (!wroteKey) {
|
|
print key "=" value
|
|
wroteKey = 1
|
|
}
|
|
next
|
|
}
|
|
{ print }
|
|
END {
|
|
if (sawSection && inSection && !wroteKey) {
|
|
print key "=" value
|
|
} else if (!sawSection) {
|
|
print ""
|
|
print "[" section "]"
|
|
print key "=" value
|
|
}
|
|
}
|
|
' "$filePath" > "$tempFile" && mv -- "$tempFile" "$filePath"
|
|
rm -f -- "$tempFile"
|
|
}
|
|
|
|
fileManager="${1:-}"
|
|
fileManager="${fileManager##*/}"
|
|
|
|
case "$fileManager" in
|
|
thunar)
|
|
command -v xfconf-query > /dev/null || exit 0
|
|
xfconf-query -c thunar -p /last-view -s ThunarDetailsView > /dev/null 2>&1 || true
|
|
;;
|
|
pcmanfm)
|
|
set_ini_key "${XDG_CONFIG_HOME:-${HOME}/.config}/pcmanfm/default/pcmanfm.conf" "ui" "view_mode" "list"
|
|
;;
|
|
pcmanfm-qt)
|
|
set_ini_key "${XDG_CONFIG_HOME:-${HOME}/.config}/pcmanfm-qt/lxqt/settings.conf" "FolderView" "Mode" "list"
|
|
;;
|
|
esac
|