fix: optimize file management in scripts

no need to `cat` into `grep`/`sed`
This commit is contained in:
swy7ch 2020-05-20 19:24:34 +02:00 committed by swytch
parent a91ea4f87e
commit 77aab67fca
3 changed files with 6 additions and 6 deletions

View File

@ -12,11 +12,11 @@
parse(){
if [ "$1" = "@" ]; then
cat "$file" | grep "$1" | awk -F '{' '{print $2} ' | tr ',' '\n' | sort -r | sed '/^[[:space:]]*$/d'
grep "$1" "$file" | awk -F '{' '{print $2} ' | tr ',' '\n' | sort -r | sed '/^[[:space:]]*$/d'
elif [ "$1" = "keywords" ]; then
cat "$file" | grep "$1" | awk -F '"' '{print $2} ' | tr ' ' '\n' | sed 's/,//g' | sort -u | sed '/^[[:space:]]*$/d'
grep "$1" "$file" | awk -F '"' '{print $2} ' | tr ' ' '\n' | sed 's/,//g' | sort -u | sed '/^[[:space:]]*$/d'
else
cat "$file" | grep "$1" | sed "s/,$//g" | awk -F '"' '{print $2} ' | sort | uniq
grep "$1" "$file" | sed "s/,$//g" | awk -F '"' '{print $2} ' | sort | uniq
fi
}
@ -25,7 +25,7 @@ input() {
if [ "$1" = "reference" ]; then
refinput | dmenu -i -p 'reference?' -l 10
elif [ "$1" = "doctype" ]; then
printf "$doctypes" | sed "s| |\n|g" | dmenu -i -p 'doctype?'
echo "$doctypes" | sed "s| |\n|g" | dmenu -i -p 'doctype?'
elif [ "$1" = "author" ]; then
parse "author" | dmenu -i -p 'author name? (surname, first name)' -l 10
elif [ "$1" = "keywords" ]; then

View File

@ -12,7 +12,7 @@
file="$(find $HOME/documents/bibliographies/ -type f -not -path '*/\.*' | dmenu -l 20 -p "[bibshow] which bibliography?")" # the -not -path allows find to ignore hidden files
refs_list="$(cat "$file" | sed 's/\t//g' | tr '\n' ' ' | sed 's/}\ /}\n/g')"
refs_list="$(sed 's/\t//g' "$file" | tr '\n' ' ' | sed 's/}\ /}\n/g')"
[ -z $refs_list ] && exit 1;
ref="$(echo "$refs_list" | dmenu -i -p 'infos?' -l 10)"

View File

@ -32,7 +32,7 @@ shebangtest()
}
texcompile() { \
bibliography="$(cat "$file" | grep '\bibliography')"
bibliography="$(grep '\bibliography' "$file")"
if [ -n "$bibliography" ]; then
pdflatex --output-directory="$dir" "$base" &&
bibtex "$base" &&