aboutsummaryrefslogtreecommitdiff
path: root/src/git-permalink.sh
diff options
context:
space:
mode:
Diffstat (limited to 'src/git-permalink.sh')
-rwxr-xr-xsrc/git-permalink.sh95
1 files changed, 82 insertions, 13 deletions
diff --git a/src/git-permalink.sh b/src/git-permalink.sh
index c70ca5e..f83bab3 100755
--- a/src/git-permalink.sh
+++ b/src/git-permalink.sh
@@ -1,22 +1,90 @@
#!/bin/sh
+# shellcheck disable=2034
set -eu
+MSG_USAGE_EN='Usage: git permalink [-phV] FILE [LINENO]'
+MSG_USAGE_PT='Uso: git permalink [-phV] ARQUIVO [NOLINHA]'
+MSG_USAGE_FR='Usage: git permalink [-phV] FICHIER [LINENO]'
+MSG_USAGE_EO='Uzmaniero: git permalink [-phV] ARKIVO [LINIONO]'
+
+MSG_HELP_EN='Options:
+ -p only print the link, don'"'"'t try to open it
+ -h, --help show this help message
+ -V, --version print the version number'
+MSG_HELP_PT='Opções:
+ -p somemente imprime o link, não tenta abrí-lo
+ -h, --help mostra esta mensagem de ajuda
+ -V, --version imprime o número de versão'
+MSG_HELP_FR='Options:
+ -p seulement imprimez le lien, n'"'"'essayez pas de l'"'"'ouvrir
+ -h, --help afficher ce message d'"'"'aide
+ -V, --version imprime le numeró de version'
+MSG_HELP_EO='Ebloj:
+ -p nur presas la ligon, ne provas malfermi ĝin
+ -h, --help montras ĉi tiun helpmesaĝon
+ -V, --version presas la versian numeron'
+
+MSG_MISSING_FILE_EN="Missing FILE argument."
+MSG_MISSING_FILE_PT="Faltando argumento ARQUIVO."
+MSG_MISSING_FILE_FR="L'argument FICHIER manque."
+MSG_MISSING_FILE_EO="La argumento ARKIVO mankas."
+
+MSG_UNSUPPORTED_ORIGIN_EN='Unsupported origin: %s.
+
+Add an template override to use git-permalink (see "man git-permalink.1" for instructions).'
+
+MSG_UNSUPPORTED_ORIGIN_PT='Origem sem suporte: %s.
+
+Adicione um modelo de substituição para usar o git-permalink (veja "man git-permalink.1" para mais instruções).'
+MSG_UNSUPPORTED_ORIGIN_FR='Origine n'"'"'es pas supporté: %s.
+
+Ajouter un modèle de remplacement pour utilisér git-permalink (regarde "man git-permalink.1" pour les instructions).'
+
+MSG_UNSUPPORTED_ORIGIN_EO='Origo ne estas subtenata: %s.
+
+Aldoni anstataŭan ŝablonon por uzi git-permalink (vidu "man git-permalink.1" por instrukcioj).'
+
+MSG_OPEN_EN='Opening %s'
+MSG_OPEN_PT='Abrindo %s'
+MSG_OPEN_FR='Ouverture de %s'
+MSG_OPEN_EO='Malfermado de %s'
+
+set_lang() {
+ lang="$1"
+ eval "
+MSG_USAGE=\$MSG_USAGE_$lang
+MSG_HELP=\$MSG_HELP_$lang
+MSG_MISSING_FILE=\$MSG_MISSING_FILE_$lang
+MSG_UNSUPPORTED_ORIGIN=\$MSG_UNSUPPORTED_ORIGIN_$lang
+MSG_OPEN=\$MSG_OPEN_$lang
+"
+}
+
+case "${LANG:-}" in
+ pt_BR.UTF-8*)
+ set_lang PT
+ ;;
+ fr_FR.UTF-8*)
+ set_lang FR
+ ;;
+ eo.UTF-8*)
+ set_lang EO
+ ;;
+ *)
+ set_lang EN
+ ;;
+esac
+
usage() {
- printf 'Usage: %s [-phV] FILE [LINENO]\n' "$0"
+ printf '%s\n' "$MSG_USAGE"
}
help() {
- cat <<EOF
-
-Options:
- -p only print the link, don't try to open it
- -h, --help show this help
- -V, --version print the version number
-EOF
+ printf '\n%s\n' "$MSG_HELP"
}
version() {
- echo 'git-permalink-@VERSION@ @DATE@'
+ printf 'git-permalink-@VERSION@ @DATE@\n'
}
PRINTONLY=false
@@ -25,7 +93,7 @@ if [ "${1:-}" = '-p' ]; then
shift
fi
if [ -z "${1:-}" ]; then
- printf "Missing \$FILE argument\n\n" >&2
+ printf '%s\n\n' "$MSG_MISSING_FILE" >&2
usage >&2
exit 2
fi
@@ -121,8 +189,8 @@ guess_permalink() {
github
;;
*)
- printf "Unsupported origin: %s.\n\n" "$ORIGIN" >&2
- printf 'Add an template override to use git-permalink (see "man git-permalink.1" for instructions).\n' >&2
+ # shellcheck disable=2059
+ printf "$MSG_UNSUPPORTED_ORIGIN\n" "$ORIGIN" >&2
exit 1
;;
esac
@@ -133,6 +201,7 @@ LINK="$(guess_permalink)"
if [ "$PRINTONLY" = true ]; then
echo "$LINK"
else
- echo "Opening $LINK" >&2
+ # shellcheck disable=2059
+ printf "$MSG_OPEN\n" "$LINK" >&2
xdg-open "$LINK"
fi