Skip to content

Commit c6a4eba

Browse files
chore: fix/ignore shellcheck warnings.
comment(pyenv, gf): add todos. chore(rfsn): clean up code.
1 parent dcb602e commit c6a4eba

File tree

6 files changed

+38
-22
lines changed

6 files changed

+38
-22
lines changed

chead

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
set -euo pipefail
44

5-
# Prints a Centered HEADer. i.e: the header bellow
5+
# Prints a Centered HEADer. i.e: the function header bellow.
66

77
# Dependencies:
88
# rev
@@ -12,9 +12,9 @@ set -euo pipefail
1212
Usage()
1313
{
1414
# TODO: Maybe rethink names of flags?
15-
while read; do
15+
while read -r; do
1616
printf '%s\n' "$REPLY"
17-
done <<- EOF
17+
done <<-EOF
1818
Usage: chead [OPTS] TEXT
1919
2020
-h, --help - Display this help information.
@@ -31,6 +31,7 @@ Usage()
3131
Err()
3232
{
3333
printf "Err: %s\n" "$2" 1>&2
34+
# shellcheck disable=2086
3435
(($1 > 0)) && exit $1
3536
}
3637

@@ -107,18 +108,18 @@ if [[ $MirrorStart == true ]]; then
107108
fi
108109

109110
# TODO: Add better error message ( include the actual inputs ).
110-
((${#HeaderText} + $StartCharCount + ${#PaddingChar} * 2 > $MaxLength)) &&
111-
Err 1 "The combination of all inputs is higher than '$MaxLength'"
111+
((${#HeaderText} + StartCharCount + ${#PaddingChar} * 2 > MaxLength)) \
112+
&& Err 1 "The combination of all inputs is higher than '$MaxLength'"
112113

113114
# ----------------------------------- Main ----------------------------------- #
114115

115-
PaddingLength=$(($MaxLength - ${#HeaderText} - ${#StartChar}))
116+
PaddingLength=$((MaxLength - ${#HeaderText} - ${#StartChar}))
116117

117118
if [[ $MirrorStart == true ]]; then
118-
PaddingLength=$(($PaddingLength - ${#StartChar}))
119+
PaddingLength=$((PaddingLength - ${#StartChar}))
119120
fi
120121

121-
PaddingLength=$(($PaddingLength / 2 / ${#PaddingChar} - 1))
122+
PaddingLength=$((PaddingLength / 2 / ${#PaddingChar} - 1))
122123

123124
for ((I = 0; I <= PaddingLength; I++)); do
124125
Padding+="$PaddingChar"
@@ -132,7 +133,7 @@ printf -v Result "%s%s%s%s" "$StartChar" "$Padding" "$HeaderText" "$Padding"
132133
# instead, and keep both behaviours.
133134

134135
if [[ $MirrorStart == true ]]; then
135-
printf "%s%s\n" "$Result" "$(rev <<< "$StartChar")"
136+
printf "%s%s\n" "$Result" "$(rev <<<"$StartChar")"
136137
else
137138
echo "$Result"
138139
fi

fzf/gd

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
# Fuzzy find a directory, then cd to it.
44

5-
# Notes:
6-
# Keep in mind that if you want to see the effect of cd you need to
5+
# NOTE: Keep in mind that if you want to see the effect of cd you need to
76
# source the script.
87

98
# Dependecies:
@@ -17,7 +16,7 @@ Usage()
1716
{
1817
while read -r; do
1918
printf "%s\n" "$REPLY"
20-
done <<- EOF
19+
done <<-EOF
2120
Usage: gd [OPTS] [BASEDIR]
2221
2322
-h, --help - Display this help information.
@@ -40,12 +39,14 @@ Err()
4039
printf "Err: %s\n" "$2" 1>&2
4140
if (($1 > 0)); then
4241
UnsetVars
42+
# shellcheck disable=2086
4343
return $1
4444
fi
4545
}
4646

4747
# ----------------------------- Input Processing ----------------------------- #
4848

49+
# shellcheck disable=2046
4950
(($# > 3)) && return $(Err 1 "Too many arguments.")
5051

5152
Command="cd"
@@ -58,14 +59,18 @@ while [[ -n $1 ]]; do
5859
;;
5960
--absolute | -a) Command="realpath" ;;
6061
--relative | -r) Command="echo" ;;
61-
-*) return $(Err 1 "Incorrect option(s) specified.") ;;
62+
-*)
63+
# shellcheck disable=2046
64+
return $(Err 1 "Incorrect option(s) specified.")
65+
;;
6266
*) break ;;
6367
esac
6468
shift
6569
done
6670

6771
BaseDir="${1:-$HOME}"
6872

73+
# shellcheck disable=2046
6974
[[ -d $BaseDir ]] || return $(Err 1 "Directory '$BaseDir' doesn't exists.")
7075

7176
# ----------------------------------- Main ----------------------------------- #

fzf/gf

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22

33
# Fuzzy find a file, move to that file directory, and then opens it on $EDITOR.
44

5-
# Notes:
6-
# Keep in mind that if you want to cd automatically to the file you need to
7-
# source the script. I will just recommend to create an alias/keybind.
5+
# NOTE: Keep in mind that if you want to cd automatically to the file you need
6+
# to source the script. I will just recommend to create an alias/keybind.
87
#
98
# I'm using `return`s, instead of `exit`s because this script needs to handle
109
# the case where it is `source`d instead of being run normally.
@@ -14,14 +13,16 @@
1413
# fzf
1514

1615
# TODO: Save value of $_GF_LAST_FILE_VISITED on a temp file.
16+
# TODO: Include '-a', and '-r' from GD
17+
# TODO: Merge `gd`, and `gf`.
1718

1819
# -------------------------------- Functions -------------------------------- #
1920

2021
Usage()
2122
{
2223
while read -r; do
2324
printf "%s\n" "$REPLY"
24-
done <<- EOF
25+
done <<-EOF
2526
Usage: gf [BASEDIR]
2627
2728
-h, --help - Display this help information.
@@ -42,18 +43,21 @@ Err()
4243
printf "Err: %s\n" "$2" 1>&2
4344
if (($1 > 0)); then
4445
UnsetVars
46+
# shellcheck disable=2086
4547
return $1
4648
fi
4749
}
4850

4951
FzfToFile()
5052
{
53+
# shellcheck disable=2046
5154
cd "${1%/*}" || return $(Err 1 "Wasn't possible to cd into '${1%/*}'.")
5255
$EDITOR "${1##*/}"
5356
}
5457

5558
# ----------------------------- Input Processing ----------------------------- #
5659

60+
# shellcheck disable=2046
5761
(($# > 1)) && return $(Err 1 "Too many arguments.")
5862

5963
case $1 in
@@ -65,17 +69,20 @@ case $1 in
6569
if [[ -n "$_GF_LAST_FILE_VISITED" ]]; then
6670
FzfToFile "$_GF_LAST_FILE_VISITED" && return 0 || return 1
6771
else
72+
# shellcheck disable=2046
6873
return $(Err 1 "No previous file visited.")
6974
fi
7075
;;
7176
esac
7277

7378
BaseDir="${1:-$HOME}"
7479

80+
# shellcheck disable=2046
7581
[[ -d $BaseDir ]] || return $(Err 1 "Directory '$BaseDir' doesn't exists.")
7682

7783
File=$(fd -tf -tl -H --exclude .git . "$BaseDir" | fzf -i +m --black)
7884

85+
# shellcheck disable=2046
7986
[[ -r $File ]] || return $(Err 1 "File '$File' is not readable.")
8087

8188
# ----------------------------------- Main ----------------------------------- #

python/pyenv

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ set -euo pipefail
1818
# test that edge case now.
1919
#
2020
# TODO: Verbose flag.
21+
#
22+
# TODO: --stop: stop searching searching venv after reaching `STOP` dir.
2123

2224
# -------------------------------- Functions -------------------------------- #
2325

rfsn

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,11 @@ for Argument in "$@"; do
8787
BaseName=${Argument##*/}
8888
BaseName=${BaseName,,}
8989
BaseName=${BaseName/" "/$Sep}
90-
BaseName=${BaseName/":"/"-"}
90+
BaseName=${BaseName/":"/$Sep}
9191

92-
if [[ $ForceUnderscore == true ]]; then
92+
if [[ $ForceHyphen == true ]]; then
9393
BaseName=${BaseName/"-"/$Sep}
94-
elif [[ $ForceHyphen == true ]]; then
94+
elif [[ $ForceUnderscore == true ]]; then
9595
BaseName=${BaseName/"_"/$Sep}
9696
fi
9797

up

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22

33
# Cd `up` an x amount of folders
44

5-
# notes: keep in mind that if you want to see the effect of cd you need to source the file.
5+
# NOTE: keep in mind that if you want to see the effect of cd you need to source the file.
66

77
Amount=${1:-1}
88

99
if ((Amount <= 0)); then
10+
# shellcheck disable=2086
1011
printf "You can't cd up %s times\n" $Amount 1>&2
1112
return 1
1213
fi
@@ -15,7 +16,7 @@ for ((I = 1; I <= Amount; I++)); do
1516
Level+=../
1617
done
1718

18-
cd $Level
19+
cd $Level || return 1
1920

2021
unset Amount
2122
unset Level

0 commit comments

Comments
 (0)