diff options
author | EuAndreh <eu@euandre.org> | 2021-09-20 18:11:57 -0300 |
---|---|---|
committer | EuAndreh <eu@euandre.org> | 2021-09-20 18:13:08 -0300 |
commit | 218696c0284ac1e6c361fe09dfebee43bebdc2af (patch) | |
tree | ed2bc9a62c684fb65dad40d4d03c15b819d92d58 /src/git-permalink.in | |
parent | Rework how translation is done (diff) | |
download | git-permalink-218696c0284ac1e6c361fe09dfebee43bebdc2af.tar.gz git-permalink-218696c0284ac1e6c361fe09dfebee43bebdc2af.tar.xz |
Adapt installation to new i18n.
Use the locale files over the locale variables. Adapt the "install" and
"uninstall" targets to it, and remove the locale test.
Diffstat (limited to 'src/git-permalink.in')
-rwxr-xr-x | src/git-permalink.in | 224 |
1 files changed, 88 insertions, 136 deletions
diff --git a/src/git-permalink.in b/src/git-permalink.in index aa83a07..bfe9889 100755 --- a/src/git-permalink.in +++ b/src/git-permalink.in @@ -1,99 +1,42 @@ #!/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] DOSIERO [LINIONO]' -MSG_HELP_EN='Options: +# +# Translatable strings +# + +_G() { + echo "$1" +} + +MSG_USAGE="$(_G 'Usage: git permalink [-phV] FILE [LINENO]')" +MSG_HELP="$(_G ' +Options: -p only print the link, don'"'"'t try to open it -h, --help show this help message -V, --version print the version number -See "man git-permalink" for more information.' -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 - -Veja "man git-permalink" para mais informações.' -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 +See "man git-permalink" for more information. +')" -Voir "man git-permalink" pour plus d'"'"'informations.' -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="$(_G 'Missing FILE argument.')" -Vidu "man git-permalink" por pliaj informoj.' +MSG_UNSUPPORTED_ORIGIN="$(_G 'Unsupported origin: %s. -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 DOSIERO mankas." +Add an template override to use git-permalink (see +"man git-permalink.1" for instructions).')" -MSG_UNSUPPORTED_ORIGIN_EN='Unsupported origin: %s. +MSG_OPEN="$(_G 'Opening %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 -" -} +if [ -r '@LIBEXECDIR@/@NAME@/load-locale-messages.sh' ]; then + . '@LIBEXECDIR@/@NAME@/load-locale-messages.sh' +fi -get_lang() { - # LC_MESSAGES="ll_CC.CODESET@modifier" -> ll_CC, where quotes are - # optional - locale 2>/dev/null | - grep ^LC_MESSAGES | - cut -d. -f1 | - cut -d\" -f2 | - cut -d= -f2 -} -case "$(get_lang)" in - pt*) - set_lang PT - ;; - fr*) - set_lang FR - ;; - eo*) - set_lang EO - ;; - *) - set_lang EN - ;; -esac +# +# Documentation functions +# usage() { printf '%s\n' "$MSG_USAGE" @@ -107,62 +50,10 @@ version() { printf 'git-permalink-@VERSION@ @DATE@\n' } -for flag in "$@"; do - case "$flag" in - --) - break - ;; - --help) - usage - help - exit - ;; - --version) - version - exit - ;; - *) - ;; - esac -done -PRINTONLY=false -while getopts 'phV' flag; do - case "$flag" in - p) - PRINTONLY=true - ;; - h) - usage - help - exit - ;; - V) - version - exit - ;; - *) - usage >&2 - exit 2 - ;; - esac -done - -shift $((OPTIND - 1)) - -if [ -z "${1:-}" ]; then - printf '%s\n\n' "$MSG_MISSING_FILE" >&2 - usage >&2 - exit 2 -fi - -FILE="$1" -MYLINENO="${2:-}" -COMMIT="$(git rev-parse HEAD)" -ORIGIN="$(git config remote.origin.url)" -OVERRIDE_CF="$(git config git-permalink.template-commit-file ||:)" -OVERRIDE_FC="$(git config git-permalink.template-file-commit ||:)" -REPOSITORY="$(basename "$PWD")" +# +# Core functions +# normalize_origin() { if echo "$ORIGIN" | grep -q '^git@'; then @@ -288,6 +179,67 @@ guess_permalink() { fi } + +# +# Main +# + +for flag in "$@"; do + case "$flag" in + --) + break + ;; + --help) + usage + help + exit + ;; + --version) + version + exit + ;; + *) + ;; + esac +done + +PRINTONLY=false +while getopts 'phV' flag; do + case "$flag" in + p) + PRINTONLY=true + ;; + h) + usage + help + exit + ;; + V) + version + exit + ;; + *) + usage >&2 + exit 2 + ;; + esac +done +shift $((OPTIND - 1)) + +if [ -z "${1:-}" ]; then + printf '%s\n\n' "$MSG_MISSING_FILE" >&2 + usage >&2 + exit 2 +fi + +FILE="$1" +MYLINENO="${2:-}" +COMMIT="$(git rev-parse HEAD)" +ORIGIN="$(git config remote.origin.url)" +OVERRIDE_CF="$(git config git-permalink.template-commit-file ||:)" +OVERRIDE_FC="$(git config git-permalink.template-file-commit ||:)" +REPOSITORY="$(basename "$PWD")" + LINK="$(guess_permalink)" if [ "$PRINTONLY" = true ]; then echo "$LINK" |