shell-scripts: Use [[ instead of [ where possible

Replace all occurrences of [ with [[ in bash and zsh scripts and
configs.
Performance wise it makes sense to use the builtin instead of calling an
external command also when from a functionality stand point `test` would
suffice.
This commit is contained in:
2020-10-03 01:29:29 +02:00
parent 29d28a25ee
commit 4cb445c2b5
14 changed files with 64 additions and 64 deletions

View File

@@ -12,7 +12,7 @@ if (( ! idx )); then
fi
local style="${@[$idx]#-style}" prefix=""
if [ -n "$style" ]; then
if [[ -n "$style" ]]; then
# Flag was given in form -style=<style>
style="${style#=}"
prefix="-style="
@@ -21,7 +21,7 @@ else
(( idx++ ))
style="${@[$idx]}"
fi
if [ ! -e "$style" ]; then
if [[ ! -e "$style" ]]; then
# Argument is not a file and thus probably a valid style string that can
# be passes to clang-format
command clang-format "$@"

View File

@@ -7,7 +7,7 @@
local toplevel="$(git rev-parse --show-toplevel)" || return
# Exit if no arguements were given
[ $# -gt 0 ] || return
[[ $# -gt 0 ]] || return
local separator=""
for arg in "$@"; do
@@ -16,11 +16,11 @@ for arg in "$@"; do
# argument relative from git toplevel
local arg_from_git="${${arg:A}##$toplevel/}"
# argument has to exist
[ -e "$arg" ] || continue
[[ -e "$arg" ]] || continue
# argument has to exist in repo
[ -e "$toplevel/$arg_from_git" ] || continue
[[ -e "$toplevel/$arg_from_git" ]] || continue
# has to be a submodule
[ -e "$toplevel/.git/modules/$arg_from_git" ] || continue
[[ -e "$toplevel/.git/modules/$arg_from_git" ]] || continue
git submodule deinit -f "$arg"
echo "command rm -rf \"$toplevel/.git/modules/$arg_from_git\""

View File

@@ -52,7 +52,7 @@ local -a fzf_args=(
# Execute git show on the commit as preview.
"--preview" "
out=\"\$(echo {} | sed -Ee \"$del_ansi\" -e \"$commit_hash\")\"
if [ \"\$out\" ]; then
if [[ \"\$out\" ]]; then
git show \"${(j:%n:)format}\" \"$date\" $colors \"\$out\" \
| diff-so-fancy
fi

View File

@@ -20,9 +20,9 @@ builtin local -a dirs files
# All other arguments are kept.
for arg in "$@"; do
shift
if [ -d "$arg" ]; then
if [[ -d "$arg" ]]; then
dirs+="$arg"
elif [ -e "$arg" ]; then
elif [[ -e "$arg" ]]; then
files+="$arg"
else
set -- "$@" "$arg"
@@ -36,7 +36,7 @@ fi
# Do not separate files and directories if -d flag was specified.
while getopts d flag 2>/dev/null; do
if [ "$flag" = "d" ]; then
if [[ "$flag" = "d" ]]; then
command ls "$@" -- "${files[@]}" "${dirs[@]}"
return
fi