-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfix-cedilla-popos.sh
More file actions
executable file
·287 lines (234 loc) · 9.59 KB
/
fix-cedilla-popos.sh
File metadata and controls
executable file
·287 lines (234 loc) · 9.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
#!/bin/bash
#
# fix-cedilla-wayland
#
# Corrige a cedilha (ç) em aplicações Chromium/Electron (VS Code, Chrome, etc.)
# no Wayland (COSMIC/Pop!_OS). Essas aplicações ignoram o ~/.XCompose e usam
# sua própria lógica interna de dead keys, onde dead_acute + c = ć (errado).
#
# A solução é usar o fcitx5 como input method, que intercepta as teclas ANTES
# de chegarem ao Chromium/Electron e aplica as regras corretas do .XCompose.
#
# O que este script faz:
# 1. Gera o ~/.XCompose com as regras de cedilha (dead_acute+c → ç)
# 2. Instala o fcitx5 e seus módulos frontend (GTK3, GTK4, Qt5)
# 3. Configura as variáveis de ambiente (GTK_IM_MODULE, QT_IM_MODULE, XMODIFIERS)
# 4. Configura o fcitx5 com layout us-intl e autostart
#
# Testado em: Pop!_OS 24.04 + COSMIC (Wayland)
# Requer: sudo (para instalar pacotes e editar /etc/environment)
#
# Uso: ./fix-cedilla-wayland.sh
# Reverter: ./fix-cedilla-wayland.sh --revert
set -euo pipefail
BOLD=$(tput bold 2>/dev/null || echo "")
RESET=$(tput sgr0 2>/dev/null || echo "")
GREEN=$(tput setaf 2 2>/dev/null || echo "")
YELLOW=$(tput setaf 3 2>/dev/null || echo "")
RED=$(tput setaf 1 2>/dev/null || echo "")
LANG=${LANG:=pt_BR.UTF-8}
COMPOSE_DIR="/usr/share/X11/locale"
USER_COMPOSE="$HOME/.XCompose"
PROGNAME="${0##*/}"
FCITX5_PACKAGES=(
fcitx5
fcitx5-config-qt
fcitx5-frontend-gtk3
fcitx5-frontend-gtk4
fcitx5-frontend-qt5
)
log_info() { echo "${GREEN}[INFO]${RESET} $*"; }
log_warn() { echo "${YELLOW}[WARN]${RESET} $*" >&2; }
log_error() { echo "${RED}[ERRO]${RESET} $*" >&2; }
# ─── Revert ──────────────────────────────────────────────────────────────────
revert() {
echo "${BOLD}Revertendo alterações...${RESET}"
echo
# Restaurar .XCompose
if [ -f "${USER_COMPOSE}.ORIGINAL" ]; then
mv -f "${USER_COMPOSE}.ORIGINAL" "${USER_COMPOSE}"
log_info "Restaurado ${USER_COMPOSE} a partir do backup."
else
rm -f "${USER_COMPOSE}"
log_info "Removido ${USER_COMPOSE}."
fi
# Restaurar /etc/environment
sudo sed -i '/^GTK_IM_MODULE=/d' /etc/environment
sudo sed -i '/^QT_IM_MODULE=/d' /etc/environment
log_info "Removidas variáveis de IM do /etc/environment."
# Restaurar pop-im-ibus.sh
sudo tee /etc/profile.d/pop-im-ibus.sh > /dev/null << 'EOF'
export GTK_IM_MODULE="ibus"
export QT_IM_MODULE="ibus"
export XMODIFIERS="@im=ibus"
EOF
log_info "Restaurado /etc/profile.d/pop-im-ibus.sh para ibus."
# Remover autostart do fcitx5
rm -f ~/.config/autostart/org.fcitx.Fcitx5.desktop
log_info "Removido autostart do fcitx5."
# Remover config do fcitx5
rm -f ~/.config/fcitx5/profile
log_info "Removido perfil do fcitx5."
# Remover flags de Electron/Chromium (se existirem)
rm -f ~/.config/code-flags.conf ~/.config/chrome-flags.conf
log_info "Removidos arquivos de flags do Chromium/Electron."
echo
echo "${BOLD}Revert completo.${RESET} Reinicie o computador para aplicar."
exit 0
}
# ─── Verificações ────────────────────────────────────────────────────────────
check_prerequisites() {
if ! command -v apt &>/dev/null; then
log_error "Este script requer apt (Debian/Ubuntu/Pop!_OS)."
exit 1
fi
if ! command -v sudo &>/dev/null; then
log_error "Este script requer sudo."
exit 1
fi
}
# ─── Passo 1: ~/.XCompose ────────────────────────────────────────────────────
setup_xcompose() {
log_info "Configurando ${USER_COMPOSE}..."
# Encontrar compose file do sistema para o locale atual
local system_compose
system_compose="${COMPOSE_DIR}/$(sed -ne "s/^\([^:]*\):[ \t]*${LANG}/\1/p" <"${COMPOSE_DIR}/compose.dir" | head -1)"
if [ -z "${system_compose}" ] || [ ! -s "${system_compose}" ]; then
log_warn "Não foi possível encontrar compose file para ${LANG}."
log_info "Usando en_US.UTF-8 como fallback."
system_compose="${COMPOSE_DIR}/en_US.UTF-8/Compose"
fi
if [ ! -s "${system_compose}" ]; then
log_error "Compose file não encontrado: ${system_compose}"
exit 1
fi
# Backup do .XCompose existente
if [ -s "${USER_COMPOSE}" ]; then
log_warn "${USER_COMPOSE} já existe. Salvando backup em ${USER_COMPOSE}.ORIGINAL"
rm -f "${USER_COMPOSE}.ORIGINAL"
cp -f "${USER_COMPOSE}" "${USER_COMPOSE}.ORIGINAL"
fi
# Gerar .XCompose substituindo ć/Ć por ç/Ç
sed -e 's/\xc4\x87/\xc3\xa7/g' \
-e 's/\xc4\x86/\xc3\x87/g' <"${system_compose}" >"${USER_COMPOSE}"
log_info "~/.XCompose criado com regras de cedilha."
}
# ─── Passo 2: Instalar fcitx5 ───────────────────────────────────────────────
install_fcitx5() {
log_info "Instalando fcitx5..."
# Verificar se já está instalado
local missing=()
for pkg in "${FCITX5_PACKAGES[@]}"; do
if ! dpkg -s "$pkg" &>/dev/null; then
missing+=("$pkg")
fi
done
if [ ${#missing[@]} -eq 0 ]; then
log_info "fcitx5 já está instalado."
return
fi
log_info "Pacotes a instalar: ${missing[*]}"
sudo apt update -qq
sudo apt install -y "${missing[@]}"
log_info "fcitx5 instalado com sucesso."
}
# ─── Passo 3: Variáveis de ambiente ─────────────────────────────────────────
setup_environment() {
log_info "Configurando variáveis de ambiente..."
# /etc/environment
sudo sed -i '/^GTK_IM_MODULE=/d' /etc/environment
sudo sed -i '/^QT_IM_MODULE=/d' /etc/environment
echo "GTK_IM_MODULE=fcitx" | sudo tee -a /etc/environment > /dev/null
echo "QT_IM_MODULE=fcitx" | sudo tee -a /etc/environment > /dev/null
log_info "Atualizado /etc/environment."
# /etc/profile.d/pop-im-ibus.sh (Pop!_OS específico)
if [ -f /etc/profile.d/pop-im-ibus.sh ]; then
sudo tee /etc/profile.d/pop-im-ibus.sh > /dev/null << 'EOF'
export GTK_IM_MODULE=fcitx
export QT_IM_MODULE=fcitx
export XMODIFIERS="@im=fcitx"
EOF
log_info "Atualizado /etc/profile.d/pop-im-ibus.sh para fcitx."
fi
}
# ─── Passo 4: Configurar fcitx5 ─────────────────────────────────────────────
configure_fcitx5() {
log_info "Configurando fcitx5..."
# Perfil com layout us-intl
mkdir -p ~/.config/fcitx5
cat > ~/.config/fcitx5/profile << 'EOF'
[Groups/0]
Name=Default
Default Layout=us-intl
DefaultIM=keyboard-us-intl
[Groups/0/Items/0]
Name=keyboard-us-intl
Layout=
[GroupOrder]
0=Default
EOF
log_info "Perfil fcitx5 criado com layout us-intl."
# Autostart
mkdir -p ~/.config/autostart
if [ -f /usr/share/applications/org.fcitx.Fcitx5.desktop ]; then
cp /usr/share/applications/org.fcitx.Fcitx5.desktop ~/.config/autostart/
log_info "Autostart do fcitx5 configurado."
else
log_warn "Arquivo .desktop do fcitx5 não encontrado. Configure o autostart manualmente."
fi
}
# ─── Passo 5: Limpar flags antigos ──────────────────────────────────────────
cleanup_old_workarounds() {
local cleaned=false
for f in ~/.config/code-flags.conf ~/.config/chrome-flags.conf ~/.config/electron-flags.conf; do
if [ -f "$f" ]; then
rm -f "$f"
log_info "Removido $f (não é mais necessário)."
cleaned=true
fi
done
if [ "$cleaned" = false ]; then
log_info "Nenhum workaround antigo para limpar."
fi
}
# ─── Main ────────────────────────────────────────────────────────────────────
main() {
echo
echo "${BOLD}══════════════════════════════════════════════════════${RESET}"
echo "${BOLD} Fix Cedilha — Wayland/COSMIC (Pop!_OS) ${RESET}"
echo "${BOLD}══════════════════════════════════════════════════════${RESET}"
echo
echo " Este script corrige a cedilha (ç) em apps Chromium/Electron"
echo " (VS Code, Chrome, etc.) no Wayland, usando fcitx5."
echo
# Checar se é revert
if [[ "${1:-}" == "--revert" ]]; then
revert
fi
check_prerequisites
echo "${BOLD}Passo 1/5:${RESET} Configurando ~/.XCompose"
setup_xcompose
echo
echo "${BOLD}Passo 2/5:${RESET} Instalando fcitx5"
install_fcitx5
echo
echo "${BOLD}Passo 3/5:${RESET} Configurando variáveis de ambiente"
setup_environment
echo
echo "${BOLD}Passo 4/5:${RESET} Configurando fcitx5"
configure_fcitx5
echo
echo "${BOLD}Passo 5/5:${RESET} Limpando workarounds antigos"
cleanup_old_workarounds
echo
echo "${BOLD}══════════════════════════════════════════════════════${RESET}"
echo "${GREEN}${BOLD} Configuração completa!${RESET}"
echo "${BOLD}══════════════════════════════════════════════════════${RESET}"
echo
echo " Reinicie o computador para aplicar as mudanças."
echo
echo " Para reverter todas as alterações:"
echo " ${BOLD}./${PROGNAME} --revert${RESET}"
echo
}
main "$@"