fix: optimize file management in scripts
no need to `cat` into `grep`/`sed`
This commit is contained in:
parent
a91ea4f87e
commit
77aab67fca
@ -12,11 +12,11 @@
|
|||||||
|
|
||||||
parse(){
|
parse(){
|
||||||
if [ "$1" = "@" ]; then
|
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
|
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
|
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
|
fi
|
||||||
}
|
}
|
||||||
@ -25,7 +25,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
|
||||||
printf "$doctypes" | sed "s| |\n|g" | dmenu -i -p 'doctype?'
|
echo "$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
|
||||||
|
@ -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
|
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;
|
[ -z $refs_list ] && exit 1;
|
||||||
|
|
||||||
ref="$(echo "$refs_list" | dmenu -i -p 'infos?' -l 10)"
|
ref="$(echo "$refs_list" | dmenu -i -p 'infos?' -l 10)"
|
||||||
|
@ -32,7 +32,7 @@ shebangtest()
|
|||||||
}
|
}
|
||||||
|
|
||||||
texcompile() { \
|
texcompile() { \
|
||||||
bibliography="$(cat "$file" | grep '\bibliography')"
|
bibliography="$(grep '\bibliography' "$file")"
|
||||||
if [ -n "$bibliography" ]; then
|
if [ -n "$bibliography" ]; then
|
||||||
pdflatex --output-directory="$dir" "$base" &&
|
pdflatex --output-directory="$dir" "$base" &&
|
||||||
bibtex "$base" &&
|
bibtex "$base" &&
|
||||||
|
Reference in New Issue
Block a user