From 845f0b00e10a07e2d6ccdb84bc8768490e09fafc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Fr=C3=A9rot?= Date: Fri, 27 Dec 2024 23:27:31 +0100 Subject: [PATCH] using [[ instead of [ in conditionals --- rtenets | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/rtenets b/rtenets index 564a37e..861f2b5 100755 --- a/rtenets +++ b/rtenets @@ -82,7 +82,7 @@ check_api_prerequisites() { # ----------------- Gitea API commands ----------------------- get_gitea_token(){ - if [ -f token ]; then + if [[ -f token ]]; then read TOKEN < token else TOKEN="$(enter "gitea token: ")" @@ -94,13 +94,15 @@ get_gitea_token(){ gitea() { check_api_prerequisites - if [ -z ${TOKEN+x} ]; then + if [[ -z ${TOKEN+x} ]]; then get_gitea_token fi local method="$1" local request="$2" - \curl -X "${request}" -H "Content-Type: application/json" -H "Authorization: token ${TOKEN}" "${ENDPOINT}/${method}" + \curl -X "${request}" \ + -H "Content-Type: application/json" \ + -H "Authorization: token ${TOKEN}" "${ENDPOINT}/${method}" } # ----------------- Git commands ----------------------- @@ -109,7 +111,7 @@ gitea() { set_git_config() { local param="$1" local value='' - while ! [ -n "${value}" ]; do + while ! [[ -n "${value}" ]]; do value="$(enter "new value for ${param}: ")" done \git config --global "${param}" "${value}" @@ -121,7 +123,7 @@ set_git_config() { get_git_config() { local param="$1" local value="$(git config "${param}")" - if ! [ -n "${value}" ]; then + if ! [[ -n "${value}" ]]; then warning "git ${param} is unset" value="$(set_git_config "${param}")" fi @@ -150,7 +152,7 @@ script_stub() { local script_name="$1" local start_phrase="$2" - if ! [ -f "${script_name}" ]; then + if ! [[ -f "${script_name}" ]]; then mkdir -p "$(dirname "${script_name}")" cat << STUB > "${script_name}" #!/usr/bin/env bash @@ -171,7 +173,7 @@ STUB fetch_licence() { local licence="COPYING" - if ! [ -f "${licence}" ]; then + if ! [[ -f "${licence}" ]]; then if has_command curl; then info "setting licence to GPL by default, see https://www.gnu.org/licenses for more options" \curl "https://www.gnu.org/licenses/gpl-3.0.txt" > "${licence}" @@ -185,7 +187,7 @@ fetch_licence() { create_readme() { local readme="README.md~" - if ! [ -f "${readme}" ]; then + if ! [[ -f "${readme}" ]]; then local project_name="$(enter "project name: ")" local project_desc="$(enter "project short description: ")" @@ -222,7 +224,7 @@ READMEMSG } create_authors_file() { - if ! [ -f AUTHORS ]; then + if ! [[ -f AUTHORS ]]; then printf "%s\\n" "${USER} <${EMAIL}> ${AFFILIATION}" > AUTHORS fi }