extended trailing whitespace script

This commit is contained in:
quak
2026-03-12 00:57:16 +01:00
parent ec030666cd
commit bde68cd4be
3 changed files with 102 additions and 54 deletions

View File

@@ -1,37 +0,0 @@
#!/usr/bin/env bash
source process-status.sh
function set_reminder {
message_reminder=$(
cat <<'EOF'
enter reminder message to display when the timer rings
EOF
)
message_time="$(
cat <<'EOF'
enter reminder time in one of the following formats:
`18:00`
`<time> + 5 minutes` - time can be `now`
EOF
)"
if ! is_process_running "atd.service"; then
notify-send "ERROR" "[atd.service] is not running"
fi
reminder="$(fuzzel --dmenu)"
if [[ -z "${reminder}" ]]; then return 1; fi
time="$(fuzzel --dmenu)"
if [[ -z "${time}" ]]; then return 1; fi
if ! $(echo "notify-send '${reminder}'" | at "${time}"); then
notify-send "failed to set reminder"
return
fi
notify-send "set reminder at ${time}"
}
set_reminder

View File

@@ -1,23 +1,107 @@
#!/usr/bin/env bash
files=($(find . -not -path "*/.git/*" -type f -exec grep -Iq . {} \; -print))
unset trailing_whitespace
function remove-whitespace {
for file in ${files[@]}; do
sed -i 's/\r$//' ${file}
if [[ -n "$(sed -ne '/[[:space:]]$/p' ${file})" ]]; then
sed -i 's/[[:space:]]$//' ${file}
trailing_whitespace+="${file}\n"
unset line_endings
unset help
unset quiet
unset files
for arg in $@; do
case ${arg} in
"-e" | "--eol" | "--end-of-line")
line_endings="true"
continue
;;
"-h" | "--help" | "-help")
help="true"
continue
;;
"-n" | "--quiet")
quiet="true"
continue
;;
*) ;;
esac
if [[ -f "${arg}" ]]; then
grep -Iq . "${arg}" && files=(${files} "${arg}")
continue
fi
if [[ -d "${arg}" ]]; then
files=(${files} $(find "${arg}" \
-not -path "*/.git/*" \
-not -name "*.lst" \
-not -name "*.map" \
-not -name "*.svd" \
-not -name "*.sym" \
-type f \
-exec grep -Iq . {} \; \
-print))
continue
fi
done
## search current directory if no argument is provided
if [[ -z "${files[@]}" ]]; then
files=($(find . \
-not -path "*/.git/*" \
-not -name "*.lst" \
-not -name "*.map" \
-not -name "*.svd" \
-not -name "*.sym" \
-type f \
-exec grep -Iq . {} \; \
-print))
fi
done
echo ""
if [[ -n "${trailing_whitespace}" ]]; then
tput setaf 1
tput smso
echo "[ DO NOT LEAVE TRAILING WHITE SPACE IN PLAIN TEXT FILES !!! ]"
tput sgr0
if [[ -n "${dir_arg}" ]] && [[ -n "${file_arg}" ]]; then
help="true"
fi
if [[ -n "${help}" ]]; then
echo "Usage: remove-whitespace [-h] [-n] path [path]"
echo ""
echo "Remove trailing whitespace from plain text files."
echo "Path points to either a file or directory, or both."
echo "Directories are search recursively for non binary."
echo "If no paths are provided, the current working"
echo "directory is search for plain text files."
echo ""
echo "Options:"
echo " -e, --eol,"
echo " --end-of-line convert all line endings to unix style"
echo " line endings"
echo " -h, --help show this help"
echo " -n, --quiet suppress output"
return 0
fi
unset trailing_whitespace
for file in ${files[@]}; do
sed -i 's/\r$//' ${file}
if [[ -n "$(sed -ne '/[[:blank:]]\+\r\?$/p' ${file})" ]]; then
if [[ -n "${line_endings}" ]]; then
sed -i 's/[[:blank:]]\+\(\r\?\)$//' ${file}
else
sed -i 's/[[:blank:]]\+\(\r\?\)$/\1/' ${file}
fi
trailing_whitespace+="${file}\n"
fi
done
echo ""
echo "The following files contained whitespace:"
echo -e "${trailing_whitespace}"
fi
if [[ -z "${quiet}" ]] &&
[[ -n "${trailing_whitespace}" ]]; then
tput setaf 1
tput smso
echo "[ DO NOT LEAVE TRAILING WHITE SPACE IN PLAIN TEXT FILES !!! ]"
tput sgr0
echo ""
echo "The following files contained whitespace:"
echo -e "${trailing_whitespace}"
fi
}