Skip to content

Instantly share code, notes, and snippets.

@naaando
Last active March 24, 2018 20:52
Show Gist options
  • Save naaando/ae426b83d77bde06e1c58cf24175e97d to your computer and use it in GitHub Desktop.
Save naaando/ae426b83d77bde06e1c58cf24175e97d to your computer and use it in GitHub Desktop.
#!/bin/sh
# Color table
red='\033[0;31m'
green='\033[0;32m'
blue='\033[0;34m'
purple='\033[0;35m'
cyan='\033[0;36m'
yellow='\033[1;33m'
normal='\033[0m'
appdata_list="/usr/share/applications /usr/local/share/applications $HOME/.local/share/applications"
string_contains () {
string="${1}"
substring="${2}"
if test "${string#*$substring}" != "$string"; then
return 0
else
return 1
fi
}
backup () {
if (test -e "${1}.backup");then
rm "${1}.backup" -i
fi
cp "${1}" "${1}".backup
echo "${blue}Info: ${normal}Gerando backup em ${yellow}$(dirname ${1})${normal}"
}
fix_exec () {
executable=$(cat "${1}" | grep ^Exec | grep -Eo '([\/]\S+)')
if (test -e $executable); then
backup "${1}"
executable=$(echo "$executable" | sed -rn 's/(\/)/\\\//gp')
sed -ri "/^Exec=.*/ s/(^Exec=).*/\1env QT_IM_MODULE=xim "$executable" -- %u/" "${1}"
echo "${blue}Info: ${normal}Atualizando atalho"
else
echo "${red}Erro: ${normal}O executavél do telegram não foi encontrado"
fi
}
main () {
find="telegram"
for directory in $appdata_list; do
for file in $directory/*; do
for char in $find; do
if ( (string_contains $(basename "$file") "$char") && (! string_contains $(basename "$file") backup)); then
echo "Atalho encontrado ${yellow}$(basename $file)${normal} em ${yellow}$(dirname $file)${normal}"
fix_exec $file
fi
done
done
done
pkill Telegram*
}
main;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment