extended trailing whitespace script
This commit is contained in:
@@ -104,6 +104,7 @@ source_list+=("$HOME/.bash_paths")
|
||||
source_list+=("$HOME/.bash_alias")
|
||||
source_list+=("${personal_scripts}/navigate_bash_setup.sh")
|
||||
source_list+=("${personal_scripts}/fzf-bash-history.sh")
|
||||
source_list+=("${personal_scripts}/trailing-whitespace.sh")
|
||||
source_list+=("${personal_scripts}/colors.sh")
|
||||
source_list+=("${personal_scripts}/dunst.sh")
|
||||
source_list+=("$HOME/.cargo/env")
|
||||
|
||||
@@ -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
|
||||
@@ -1,18 +1,100 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
files=($(find . -not -path "*/.git/*" -type f -exec grep -Iq . {} \; -print))
|
||||
function remove-whitespace {
|
||||
|
||||
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
|
||||
|
||||
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 '/[[:space:]]$/p' ${file})" ]]; then
|
||||
sed -i 's/[[:space:]]$//' ${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 ""
|
||||
|
||||
if [[ -n "${trailing_whitespace}" ]]; then
|
||||
if [[ -z "${quiet}" ]] &&
|
||||
[[ -n "${trailing_whitespace}" ]]; then
|
||||
tput setaf 1
|
||||
tput smso
|
||||
echo "[ DO NOT LEAVE TRAILING WHITE SPACE IN PLAIN TEXT FILES !!! ]"
|
||||
@@ -21,3 +103,5 @@ if [[ -n "${trailing_whitespace}" ]]; then
|
||||
echo "The following files contained whitespace:"
|
||||
echo -e "${trailing_whitespace}"
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user