Last active
July 21, 2018 19:05
-
-
Save ZeppLu/637353565e5be6b8275a859f7c412f8c to your computer and use it in GitHub Desktop.
Revisions
-
ZeppLu revised this gist
Jul 21, 2018 . 1 changed file with 21 additions and 7 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4,12 +4,19 @@ declare -A entries=( # desktop file, used when you launch konsole from most of the launchers ["/usr/share/applications/org.kde.konsole.desktop"]="$HOME/.local/share/applications/org.kde.konsole.desktop" ["/usr/share/applications/org.kde.konsole.desktop"]="$HOME/.local/share/applications/org.kde.konsole.desktop" # KDE only, used when you launch a shell script with konsole from dolphin ["/usr/share/kservices5/ServiceMenus/konsolerun.desktop"]="$HOME/.local/share/kservices5/ServiceMenus/konsolerun.desktop" # KDE only, used when you click "Open konsole here" from dolphin's context menu ["/usr/share/kservices5/ServiceMenus/konsolehere.desktop"]="$HOME/.local/share/kservices5/ServiceMenus/konsolehere.desktop" ) declare -A apps=( # some applications launched in terminal mode ["/usr/share/applications/vim.desktop"]="$HOME/.local/share/applications/vim.desktop" ["/usr/share/applications/htop.desktop"]="$HOME/.local/share/applications/htop.desktop" ) get_current_scaling_factor() { # this function only works on KDE config_file="$HOME/.config/kdeglobals" @@ -24,29 +31,36 @@ get_current_scaling_factor() { fill_and_install() { src="$1" dst="$2" patterns="$3" if [ -f "$dst" ]; then echo $dst already present, backing it up... mv "$dst" "$dst.backup" fi echo Generating $dst based on $src... sed "${patterns[@]}" "$src" > "$dst" } main() { factor="$(get_current_scaling_factor)" reversed_factor="$(bc <<< "scale=10; 1 / ${factor}")" echo Current scaling factor is $factor, will set QT_SCALE_FACTOR to $reversed_factor for src in "${!entries[@]}"; do dst="${entries[$src]}" # pattern used in sed patterns=("-e" "s/^Exec=konsole/Exec=QT_SCALE_FACTOR=$reversed_factor konsole/") fill_and_install "$src" "$dst" "$patterns" done for src in "${!apps[@]}"; do dst="${apps[$src]}" patterns=("-e" "s/^Exec=\(.*\)/Exec=QT_SCALE_FACTOR=$reversed_factor konsole -e \1/" "-e" "s/^Terminal=true$/Terminal=false/") fill_and_install "$src" "$dst" "$patterns" done } main -
ZeppLu renamed this gist
Jul 21, 2018 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
ZeppLu created this gist
Jul 21, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,52 @@ #!/bin/bash # key=src, value=dst declare -A entries=( # desktop file, used when you launch konsole from most of the launchers ["/usr/share/applications/org.kde.konsole.desktop"]="$HOME/.local/share/applications/org.kde.konsole.desktop" # KDE only, used when you launch a shell script with konsole from dolphin ["/usr/share/kservices5/ServiceMenus/konsolerun.desktop"]="$HOME/.local/share/kservices5/ServiceMenus/konsolerun.desktop" # KDE only, used when you click "Open konsole here" from dolphin's context menu ["/usr/share/kservices5/ServiceMenus/konsolehere.desktop"]="$HOME/.local/share/kservices5/ServiceMenus/konsolehere.desktop" ) get_current_scaling_factor() { # this function only works on KDE config_file="$HOME/.config/kdeglobals" section_name="KScreen" key_name="ScaleFactor" # XXX: section name is ignored for now factor="$(grep "^${key_name}=" "$config_file" | cut -d'=' -f2)" echo ${factor} } fill_and_install() { src="$1" dst="$2" factor="$3" reversed_factor="$(bc <<< "scale=10; 1 / ${factor}")" if [ -f "$dst" ]; then echo $dst already present, backing it up... mv "$dst" "$dst.backup" fi echo Generating $dst based on $src... sed "s/^Exec=konsole/Exec=QT_SCALE_FACTOR=$reversed_factor konsole/" "$src" > "$dst" } main() { factor="$(get_current_scaling_factor)" echo Current scaling factor is $factor for src in "${!entries[@]}"; do dst="${entries[$src]}" fill_and_install "$src" "$dst" "$factor" done } main