-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathirssi
executable file
·63 lines (53 loc) · 1.68 KB
/
irssi
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
#!/bin/sh -
# Wrapper script around irssi that
# * Makes irssi (halfway) respect the XDG basedir spec;
# * Allows storing the password encrypted and in a different location;
# Written by ayekat on a cold Wednesday afternoon in january 2017.
set -fu
readonly IRSSI_HOME=$XDG_CONFIG_HOME/irssi
readonly IRSSI_CONFIG=$IRSSI_HOME/config
readonly IRSSI_HOME_REAL=$XDG_RUNTIME_DIR/irssi
readonly IRSSI_CONFIG_REAL=$IRSSI_HOME_REAL/config
readonly IRSSI_CONFIG_MARKER=${IRSSI_CONFIG_MARKER:-@}
die()
{
retval=$(($1)); shift
{
# shellcheck disable=SC2059
printf "$@"
printf '\n'
} >&2
exit $retval
}
sedescape()
{
printf '%s' "$1" | sed 's|\\|\\\\|g;s|/|\\/|g;s|"|\\\\"|'
}
if ! mkdir -p "$IRSSI_HOME_REAL"; then
die 2 'Could not create temporary configuration directory %s' \
"$IRSSI_HOME_REAL"
fi
# Replace password if it is given:
if irssi_password_name=$(
grep -oP \
"(?<=${IRSSI_CONFIG_MARKER}IRC_PASSWORD:)[^${IRSSI_CONFIG_MARKER}]+" \
"$IRSSI_CONFIG"
); then
if ! irssi_password=$(pass show "services/$irssi_password_name"); then
die 2 'Could not obtain IRC password'
fi
# Generate config with password:
m="${IRSSI_CONFIG_MARKER}IRC_PASSWORD:[^$IRSSI_CONFIG_MARKER]\\+$IRSSI_CONFIG_MARKER"
s=$(sedescape "$irssi_password")
if ! sed "s/$m/$s/g" <"$IRSSI_CONFIG" >"$IRSSI_CONFIG_REAL"; then
die 2 'Could not generate temporary irssi configuration file in %s' \
"$IRSSI_CONFIG_REAL"
fi
else
if ! cp "$IRSSI_CONFIG" "$IRSSI_CONFIG_REAL"; then
die 2 'Could not copy configuration %s to temporary location %s' \
"$IRSSI_CONFIG" "$IRSSI_HOME_REAL"
fi
fi
# Run irssi with the generated config:
exec unwrap irssi --home="$IRSSI_HOME" --config="$IRSSI_CONFIG_REAL" "$@"