fix: change `echo` commands to `printf` commands

`printf` behaviour is more predictable then `echo` because bash is just
overdoing things
This commit is contained in:
swytch 2020-05-25 15:04:16 +02:00
parent 97ae8ca1d0
commit a94e6be43c
9 changed files with 123 additions and 122 deletions

View File

@ -26,12 +26,12 @@ services_list="netctl-auto@wlp4s0 systemd-timescyncd"
git_clone() { git_clone() {
git clone https://gitlab.com/swy7ch/$1 ~/suckless/$1 git clone https://gitlab.com/swy7ch/$1 ~/suckless/$1
echo "$1 downloaded!" printf "\n$1 downloaded!"
cd ~/$1 cd ~/$1
git remote set-url origin git@gitlab.com:swy7ch/$1 git remote set-url origin git@gitlab.com:swy7ch/$1
if [ "dotfiles" != $1 ] if [ "dotfiles" != $1 ]
git remote add upstream git://git.suckless.org/$1 git remote add upstream git://git.suckless.org/$1
echo "$1 setup complete!" printf "\n$1 setup complete!"
fi fi
cd cd
} }
@ -39,7 +39,7 @@ git_clone() {
build() { build() {
cd ~/$1 cd ~/$1
sudo make clean install sudo make clean install
echo "$1 compilation complete!" printf "\n$1 compilation complete!"
} }
install() { install() {
@ -47,7 +47,7 @@ install() {
if [ $validation = "y" ]; then if [ $validation = "y" ]; then
yay -S $APP yay -S $APP
else else
echo "Skipping $APP" printf "\nSkipping $APP"
fi fi
} }
@ -61,7 +61,7 @@ enable_systemctl() {
echo "Configuring Arch..." printf "\nConfiguring Arch..."
# Retrieving yay # Retrieving yay
# We need git # We need git
@ -70,96 +70,96 @@ git clone https://aur.archlinux.org/yay.git
cd yay cd yay
makepkg -si makepkg -si
echo "YAY is here !" printf "\nYAY is here !"
cd ~ cd ~
echo "Let's get the other apps" printf "\nLet's get the other apps"
# Installing apps # Installing apps
echo "Installing base" printf "\nInstalling base"
for app in $base_list; do for app in $base_list; do
install $app install $app
done done
echo "Done." printf "\nDone."
echo "Installing utilitaries" printf "\nInstalling utilitaries"
for app in $utilities_list; do for app in $utilities_list; do
install $app install $app
done done
echo "Done." printf "\nDone."
echo "Installing fonts" printf "\nInstalling fonts"
for app in $fonts_list; do for app in $fonts_list; do
install $app install $app
done done
echo "Done." printf "\nDone."
echo "Installing media apps" printf "\nInstalling media apps"
for app in $media_list; do for app in $media_list; do
install $app install $app
done done
echo "Done." printf "\nDone."
echo "Installing other apps" printf "\nInstalling other apps"
for app in $other_list; do for app in $other_list; do
install $app install $app
done done
echo "Done." printf "\nDone."
echo "Installing vim-plug" printf "\nInstalling vim-plug"
curl -fLo ~/.local/share/nvim/site/autoload/plug.vim --create-dirs \ curl -fLo ~/.local/share/nvim/site/autoload/plug.vim --create-dirs \
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
echo "Done." printf "\nDone."
echo "Installation complete !" printf "\nInstallation complete !"
# Symlinking the necessary stuff # Symlinking the necessary stuff
echo "Downloading personnal git repos..." printf "\nDownloading personnal git repos..."
for repo in $git_list; do for repo in $git_list; do
git_clone $repo git_clone $repo
done done
echo "Done." printf "\nDone."
echo "Compiling tools..." printf "\nCompiling tools..."
for tool in $build_list; do for tool in $build_list; do
build $tool build $tool
done done
echo "Done." printf "\nDone."
echo "" printf "\n"
echo "!!! Don't forget to link an SSH key to your account !!!" printf "\n!!! Don't forget to link an SSH key to your account !!!"
echo "!!! As of now, you can't pull nor push anything !!!" printf "\n!!! As of now, you can't pull nor push anything !!!"
echo "" printf "\n"
echo "Enabling systemctl services" printf "\nEnabling systemctl services"
for service in $services_list; do for service in $services_list; do
enable_systemctl $service enable_systemctl $service
done done
echo "Done." printf "\nDone."
echo "" printf "\n"
echo "##################################################" printf "\n##################################################"
echo "" printf "\n"
echo "Configuration complete !" printf "\nConfiguration complete !\n"

View File

@ -26,7 +26,7 @@ input() {
if [ "$1" = "reference" ]; then if [ "$1" = "reference" ]; then
refinput | dmenu -i -p 'reference?' -l 10 refinput | dmenu -i -p 'reference?' -l 10
elif [ "$1" = "doctype" ]; then elif [ "$1" = "doctype" ]; then
echo "$doctypes" | sed "s| |\n|g" | dmenu -i -p 'doctype?' printf "$doctypes" | sed "s| |\n|g" | dmenu -i -p 'doctype?'
elif [ "$1" = "author" ]; then elif [ "$1" = "author" ]; then
parse "author" | dmenu -i -p 'author name? (surname, first name)' -l 10 parse "author" | dmenu -i -p 'author name? (surname, first name)' -l 10
elif [ "$1" = "keywords" ]; then elif [ "$1" = "keywords" ]; then
@ -37,7 +37,7 @@ input() {
} }
refinput(){ refinput(){
echo "ref$(cat "$file" | grep '@' | wc -l | awk '{printf $1}')" && parse "@" printf "ref$(cat "$file" | grep '@' | wc -l | awk '{printf $1}')\n" && parse "@"
} }
doctypes="article book online techreport" doctypes="article book online techreport"
@ -105,14 +105,14 @@ while [ "$keyword_test" = "yes" ]; do
fi fi
done done
echo "@$doctype{"$reference"," >> "$file" printf "\n@$doctype{"$reference"," >> "$file"
echo -e "\tauthor = \"$author\"," >> "$file" printf "\n\tauthor = \"$author\"," >> "$file"
echo -e "\ttitle = \"$title\"," >> "$file" printf "\n\ttitle = \"$title\"," >> "$file"
echo -e "\tyear = \"$year\"," >> "$file" printf "\n\tyear = \"$year\"," >> "$file"
[ -n "$journal" ] && echo -e "\tjournal = \"$journal\"," >> "$file" [ -n "$journal" ] && printf "\n\tjournal = \"$journal\"," >> "$file"
[ -n "$volume" ] && echo -e "\tvolume = \"$volume\"," >> "$file" [ -n "$volume" ] && printf "\n\tvolume = \"$volume\"," >> "$file"
[ -n "$publisher" ] && echo -e "\tpublisher = \"$publisher\"," >> "$file" [ -n "$publisher" ] && printf "\n\tpublisher = \"$publisher\"," >> "$file"
[ -n "$url" ] && echo -e "\turl = \"$url\"," >> "$file" [ -n "$url" ] && printf "\n\turl = \"$url\"," >> "$file"
[ -n "$institution" ] && echo -e "\tinstitution = \"$institution\"," >> "$file" [ -n "$institution" ] && printf "\n\tinstitution = \"$institution\"," >> "$file"
echo -e "\tkeywords = \"$keywords\"" >> "$file" printf "\n\tkeywords = \"$keywords\"" >> "$file"
echo "}" >> "$file" printf "\n}" >> "$file"

View File

@ -16,10 +16,10 @@ file="$(find $HOME/documents/bibliographies/ -type f -not -path '*/\.*' | dmenu
refs_list="$(sed -e 's/\t//g' "$file" | tr '\n' ' ' | sed -e 's/}\ /}\n/g')" refs_list="$(sed -e 's/\t//g' "$file" | tr '\n' ' ' | sed -e 's/}\ /}\n/g')"
[ -z $refs_list ] && exit 1; [ -z $refs_list ] && exit 1;
ref="$(echo "$refs_list" | dmenu -i -p 'infos?' -l 10)" ref="$(printf "$refs_list" | dmenu -i -p 'reference?' -l 10)"
[ -z $ref ] && exit 1; [ -z $ref ] && exit 1;
output="$(echo "$ref" | sed 's/author/\n author/g' | sed 's/",/",\n/g')" output="$(printf "$ref" | sed -e 's/author/\n author/g' -e 's/",/",\n/g')"
echo "$output" | dmenu -i -p "infos" -l 10 printf "$output" | dmenu -i -p "infos" -l 10
echo "$ref" | awk -F '{' '{print $2}' | awk -F ',' '{print $1}' | xclip -selection clipboard printf "$ref" | awk -F '{' '{print $2}' | awk -F ',' '{print $1}' | xclip -selection clipboard

View File

@ -17,7 +17,7 @@
file=$(readlink -f "$1") file=$(readlink -f "$1")
dir=$(dirname "$file") dir=$(dirname "$file")
dirname=$(basename "$dir") dirname=$(basename "$dir")
base="$(echo "${file%.*}" | awk -F '/' '{printf $NF}')" base="$(printf "${file%.*}" | awk -F '/' '{printf $NF}')"
shebang=$(sed -n 1p "$file") shebang=$(sed -n 1p "$file")
sucklesstools="$(ls $XDG_CONFIG_HOME/suckless)" sucklesstools="$(ls $XDG_CONFIG_HOME/suckless)"
@ -47,7 +47,7 @@ texcompile() { \
s_build(){ s_build(){
case "$file" in case "$file" in
*config.def.h) sudo make clean install && rm -f config.h ;; *config.def.h) sudo make clean install && rm -f config.h ;;
*config.h) echo "" && echo "You should build from config.def.h !" ;; *config.h) printf "\nYou should build from config.def.h !" ;;
esac esac
exit 0 exit 0

View File

@ -14,7 +14,7 @@
# Handle SIGTRAP signals sent by refbar to update the status bar immediately. # Handle SIGTRAP signals sent by refbar to update the status bar immediately.
trap 'update' 5 trap 'update' 5
delim="|" # Set the delimiter character. delim=" | " # Set the delimiter character.
status() { \ status() { \
# Get the volume of ALSA's master volume output. # Get the volume of ALSA's master volume output.
@ -22,21 +22,22 @@ status() { \
muted="$(pamixer --get-mute)" muted="$(pamixer --get-mute)"
if [ "$muted" = "true" ]; then if [ "$muted" = "true" ]; then
echo " muted" printf " muted"
else else
echo " 墳 $volume%" printf " 墳 $volume%%"
fi fi
echo "$delim" printf "$delim"
# Wifi quality percentage and  icon if ethernet is connected. # Wifi quality percentage and  icon if ethernet is connected.
grep "^\s*w" /proc/net/wireless | awk '{ print "索", int($3 * 100 / 70) "%" }' wifi="$(grep "^\s*w" /proc/net/wireless | awk '{ print "索", int($3 * 100 / 70) "%" }')"
printf "$wifi"
eth="$(cat /sys/class/net/enp0s25/operstate)" eth="$(cat /sys/class/net/enp0s25/operstate)"
if [ "up" = "$eth" ]; then if [ "up" = "$eth" ]; then
echo "/ " printf " / "
fi fi
echo "$delim" printf "$delim"
# Will show all batteries with approximate icon for remaining power. # Will show all batteries with approximate icon for remaining power.
# Or show that the computer is plugged to a power source # Or show that the computer is plugged to a power source
@ -46,17 +47,17 @@ status() { \
do do
if [ "$AC_ON" = 0 ]; then if [ "$AC_ON" = 0 ]; then
case "$(cat "$x")" in case "$(cat "$x")" in
10[0-9]|101) echo "" ;; 10[0-9]|101) printf "" ;;
100|9[0-9]) echo " $(cat "$x")%" ;; 100|9[0-9]) printf " $(cat "$x")%%" ;;
8[0-9]|7[0-9]) echo " $(cat "$x")%" ;; 8[0-9]|7[0-9]) printf " $(cat "$x")%%" ;;
6[0-9]|5[0-9]) echo " $(cat "$x")%" ;; 6[0-9]|5[0-9]) printf " $(cat "$x")%%" ;;
4[0-9]|3[0-9]) echo " $(cat "$x")%" ;; 4[0-9]|3[0-9]) printf " $(cat "$x")%%" ;;
*) echo " $(cat "$x")%" ;; *) printf " $(cat "$x")%%" ;;
esac esac
else else
echo " $(cat "$x")%" printf " $(cat "$x")%%"
fi fi
done && echo "$delim" done && printf "$delim"
# Date and time. # Date and time.
date '+%b. %d - %I:%M%p' date '+%b. %d - %I:%M%p'

View File

@ -13,14 +13,14 @@
headers_list="$(ls | grep '.h$')" headers_list="$(ls | grep '.h$')"
sources_list="$(ls | grep '.cp*$')" sources_list="$(ls | grep '.cp*$')"
modules_list="$(echo "$sources_list" | sed 's/\.cp*//g' | tr '\n' ' ')" modules_list="$(printf "\n$sources_list" | sed 's/\.cp*//g' | tr '\n' ' ')"
targets_list="$(echo "$sources_list" | sed 's/\.cp*/\.o/g' | tr '\n' ' ')" targets_list="$(printf "\n$sources_list" | sed 's/\.cp*/\.o/g' | tr '\n' ' ')"
get_compiler(){ get_compiler(){
for source_ in "$sources_list"; do for source_ in "$sources_list"; do
case "$source_" in case "$source_" in
*.cpp) echo "g++" && return;; *.cpp) printf "\ng++" && return;;
*.c) echo "gcc";; *.c) printf "\ngcc";;
esac esac
done done
} }
@ -31,17 +31,17 @@ is_c_project(){
make_rule(){ make_rule(){
if [ "$comp" = "gcc" ]; then if [ "$comp" = "gcc" ]; then
echo "$1.o : $1.c $1.h" >> makefile printf "\n$1.o : $1.c $1.h" >> makefile
echo -e "\t\$(CC) -c $1.c \$(FLAGS)" >> makefile echo -e "\t\$(CC) -c $1.c \$(FLAGS)" >> makefile
else else
echo "$1.o : $1.cpp $1.h" >> makefile printf "\n$1.o : $1.cpp $1.h" >> makefile
echo -e "\t\$(CC) -c $1.cpp \$(FLAGS)" >> makefile echo -e "\t\$(CC) -c $1.cpp \$(FLAGS)" >> makefile
fi fi
echo "" >> makefile printf "\n" >> makefile
} }
if ! is_c_project; then if ! is_c_project; then
echo "No C/C++ project in directory. Exiting..." printf "\nNo C/C++ project in directory. Exiting..."
exit 1 exit 1
fi fi

View File

@ -11,26 +11,26 @@
###################################################################### ######################################################################
if [ -z ""$1"" ]; then if [ -z "$1" ]; then
echo "Please provide a name for your file" printf 'Please provide a name for your file\n'
elif [ -e "$1" ]; then elif [ -e "$1" ]; then
echo "This filename is already taken, please provide a different name" printf 'This filename is already taken, please provide a different name\n'
else else
touch "$1" && \ touch "$1" && \
echo "\# metadata" >> "$1" && \ printf '\# metadata' >> "$1" && \
echo '.AUTHOR "David JULIEN"' >> "$1" && \ printf '\n.AUTHOR "David JULIEN"' >> "$1" && \
echo '.TITLE' >> "$1" && \ printf '\n.TITLE' >> "$1" && \
echo '\# template' >> "$1" && \ printf '\n\# template' >> "$1" && \
echo '.PRINTSTYLE TYPESET' >> "$1" && \ printf '\n.PRINTSTYLE TYPESET' >> "$1" && \
echo '.QUOTE_STYLE QUAD' >> "$1" && \ printf '\n.QUOTE_STYLE QUAD' >> "$1" && \
echo '.SMARTQUOTES FR' >> "$1" && \ printf '\n.SMARTQUOTES FR' >> "$1" && \
echo '.ATTRIBUTE_STRING "par"' >> "$1" && \ printf '\n.ATTRIBUTE_STRING "par"' >> "$1" && \
echo '.LINEBREAK_CHAR ""' >> "$1" && \ printf '\n.LINEBREAK_CHAR ""' >> "$1" && \
echo '\# cover' >> "$1" && \ printf '\n\# cover' >> "$1" && \
echo '.COVER AUTHOR TITLE BLANKPAGE' >> "$1" && \ printf '\n.COVER AUTHOR TITLE BLANKPAGE' >> "$1" && \
echo '.DOCHEADER OFF' >> "$1" && \ printf '\n.DOCHEADER OFF' >> "$1" && \
echo '\#' >> "$1" && \ printf '\n\#' >> "$1" && \
echo '.START' >> "$1" && \ printf '\n.START' >> "$1" && \
# checks if neovim is intalled # checks if neovim is intalled
if command -v nvim > /dev/null 2>&1; then if command -v nvim > /dev/null 2>&1; then

View File

@ -25,7 +25,7 @@ touch rendu.mom
for doc in "$list"; do for doc in "$list"; do
cat "$doc" >> rendu.mom cat "$doc" >> rendu.mom
echo ".COLLATE" >> rendu.mom printf "\n.COLLATE" >> rendu.mom
done done
# Remove the last ".COLLATE" # Remove the last ".COLLATE"

View File

@ -12,69 +12,69 @@
if [ -z "$1" ]; then if [ -z "$1" ]; then
echo "Please provide a name for your file" printf "Please provide a name for your file\n"
elif [ -e $1 ]; then elif [ -e $1 ]; then
echo "This filename is already taken, please provide a different name" printf "This filename is already taken, please provide a different name\n"
else else
touch "$1" touch "$1"
echo '% metadata' >> "$1" printf '%%metadata' >> "$1"
read -p "Which type is your document? (def: article) " class read -p "Which type is your document? (def: article) " class
if [ -z "$class" ]; then if [ -z "$class" ]; then
class='article' class='article'
fi fi
echo "\\documentclass[a4paper, 12pt]{$class}" >> "$1" printf "\n\\documentclass[a4paper, 12pt]{$class}" >> "$1"
echo '' >> "$1" printf '\n' >> "$1"
read -p "Do you want colors?(y/N) " colors read -p "Do you want colors?(y/N) " colors
if [ "$colors" = "y" ]; then if [ "$colors" = "y" ]; then
echo '\usepackage[dvipsname]{xcolor}' >> "$1" printf '\n\usepackage[dvipsname]{xcolor}' >> "$1"
fi fi
read -p "Do you want hyperlinks management?(y/N) " links read -p "Do you want hyperlinks management?(y/N) " links
if [ "$links" = "y" ]; then if [ "$links" = "y" ]; then
if [ "$colors" != "y" ]; then if [ "$colors" != "y" ]; then
echo '\usepackage[dvipsname]{xcolor}' >> "$1" printf '\n\usepackage[dvipsname]{xcolor}' >> "$1"
fi fi
echo '\usepackage[colorlinks=true, urlcolor=BrickRed]{hyperref}' >> "$1" printf '\n\usepackage[colorlinks=true, urlcolor=BrickRed]{hyperref}' >> "$1"
fi fi
read -p "Do you want bibliography management?(y/N) " bibliography read -p "Do you want bibliography management?(y/N) " bibliography
if [ "$bibliography" = "y" ]; then if [ "$bibliography" = "y" ]; then
read -p "Do you want to use apacite?(y/N) " apacite read -p "Do you want to use apacite?(y/N) " apacite
if [ $apacite = "y" ]; then if [ $apacite = "y" ]; then
echo '\usepackage{apacite}' >> "$1" printf '\n\usepackage{apacite}' >> "$1"
bibstyle="apacite" bibstyle="apacite"
else else
bibstyle="unsrt" bibstyle="unsrt"
echo 'The default style is _unsrt_ (you may change it at the end of the document)' printf '\nThe default style is _unsrt_ (you may change it at the end of the document)'
fi fi
bibfile="$(basename "$(find $HOME/documents/bibliographies/ -type f -not -path '*/\.*' | dmenu -l 20 -p "which bibliography?")")" # the -not -path allows find to ignore hidden files bibfile="$(basename "$(find $HOME/documents/bibliographies/ -type f -not -path '*/\.*' | dmenu -l 20 -p "which bibliography?")")" # the -not -path allows find to ignore hidden files
if [ -z "$bibfile" ]; then if [ -z "$bibfile" ]; then
echo '' printf '\n'
echo '##################################################' printf '\n##################################################'
echo "Don't forget to specify the .bib file (\\bibliography{.bib}) at the end of the file " | fold -w 46 | sed "s/$/\ \#/g" | sed "s/^/\#\ /g" printf "\nDon't forget to specify the .bib file (\\bibliography{.bib}) at the end of the file " | fold -w 46 | sed "s/$/\ \#/g" | sed "s/^/\#\ /g"
echo '##################################################' printf '\n##################################################'
echo '' printf '\n'
fi fi
fi fi
read -p "Do you want to use another package? If so, please provide a package name; else, just press <Enter>: " package read -p "Do you want to use another package? If so, please provide a package name; else, just press <Enter>: " package
while [ -n "$package" ]; do while [ -n "$package" ]; do
echo "\usepackage{"$package"}" >> "$1" printf "\n\usepackage{"$package"}" >> "$1"
package='' package=''
read -p "Do you want to use another package? If so, please provide a package name: " package read -p "Do you want to use another package? If so, please provide a package name: " package
done done
echo '' >> "$1" printf '\n' >> "$1"
echo '\author{David JULIEN}' >> "$1" printf '\n\\author{David JULIEN}' >> "$1"
read -p "What is the title of the document? " title read -p "What is the title of the document? " title
echo "\\title{"$title"}" >> "$1" printf '\n\\title{"$title"}' >> "$1"
echo '' >> "$1" printf '\n' >> "$1"
echo '%document' >> "$1" printf '\n%%document' >> "$1"
echo '\begin{document}' >> "$1" printf '\n\\begin{document}' >> "$1"
echo '' >> "$1" printf '\n' >> "$1"
echo '\maketitle' >> "$1" printf '\n\\maketitle' >> "$1"
echo '' >> "$1" printf '\n' >> "$1"
if [ "$bibliography" = "y" ]; then if [ "$bibliography" = "y" ]; then
echo "\bibliographystyle{$bibstyle}" >> "$1" printf '\n\bibliographystyle{$bibstyle}' >> "$1"
echo "\bibliography{$HOME/documents/bibliographies/$bibfile}" >> "$1" printf '\n\bibliography{$HOME/documents/bibliographies/$bibfile}' >> "$1"
fi fi
echo '\end{document}' >> "$1" printf '\n\end{document}' >> "$1"
# check if neovim is installed # check if neovim is installed
if command -v nvim > /dev/null 2>&1; then if command -v nvim > /dev/null 2>&1; then