using [[ instead of [ in conditionals

This commit is contained in:
Lucas Frérot 2024-12-27 23:27:31 +01:00
parent 4d7fe58ec3
commit 845f0b00e1
No known key found for this signature in database
GPG Key ID: 03B54A50E3FBA7E8
1 changed files with 11 additions and 9 deletions

20
rtenets
View File

@ -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
}