commit 51009a5b5fc17b9d19c13cd810cdda767c25ff1f
parent 345d3bfe275cec50647214312e9efa65db7b3fe8
Author: Anders Damsgaard <anders@adamsgaard.dk>
Date: Thu, 11 Apr 2019 10:01:51 +0200
Add the ability to add citation for bibliography from articlesearch
Diffstat:
3 files changed, 20 insertions(+), 37 deletions(-)
diff --git a/.profile b/.profile
@@ -3,16 +3,16 @@
export EDITOR="vim"
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
-export MAILDIR=~/mail
+export MAILDIR="$HOME/mail"
export TERMINAL=st
export BROWSER=surf-open.sh
+export BIB="$HOME/articles/own/BIBnew.bib"
# nnn settings
NNN_BMS="a:$HOME/articles;"
NNN_BMS+="b:$HOME/books;"
NNN_BMS+="c:$HOME/code;"
NNN_BMS+="d:$HOME/doc;"
-NNN_BMS+="D:$HOME/code/dotfiles/links;"
NNN_BMS+="m:/mnt;"
NNN_BMS+="s:$HOME/uni/postdoc/stanford-sigma;"
NNN_BMS+="t:$HOME/tmp;"
@@ -25,26 +25,6 @@ export NNN_SCRIPT="$HOME/.config/nnn"
# shellcheck source=/dev/null
[ -f ~/.secret_env_vars ] && . ~/.secret_env_vars
-# Start ssh-agent if not already running
-# SSH_ENV="$HOME/.ssh/environment"
-# start_agent() {
-# echo "Initialising new SSH agent..."
-# /usr/bin/ssh-agent | sed 's/^echo/#echo/' > "${SSH_ENV}"
-# echo succeeded
-# chmod 600 "${SSH_ENV}"
-# . "${SSH_ENV}" > /dev/null
-# /usr/bin/ssh-add;
-# }
-
-# # Source SSH settings, if applicable
-# if [ -f "${SSH_ENV}" ]; then
-# . "${SSH_ENV}" > /dev/null
-# ps -ef | grep ${SSH_AGENT_PID} | grep ssh-agent$ > /dev/null || {
-# start_agent;
-# }
-# else
-# start_agent;
-# fi
#### PATH AND MACHINE SPECIFIC CONFIGS
@@ -52,17 +32,7 @@ export NNN_SCRIPT="$HOME/.config/nnn"
[ -d /usr/local/sbin ] && export PATH=/usr/local/sbin:$PATH
[ -d ~/local/bin ] && export PATH=~/local/bin:$PATH
[ -d ~/.local/bin ] && export PATH=~/.local/bin:$PATH
-[ -d $HOME/bin ] && export PATH=$HOME/bin:$PATH
-if [ -d ~/.linuxbrew ]; then
- export PATH=~/.linuxbrew/bin:$PATH
- export MANPATH=~/.linuxbrew/share/man:$MANPATH
- export INFOPATH=~/.linuxbrew/share/info:$INFOPATH
-fi
-if [ -d /home/linuxbrew/.linuxbrew ]; then
- export PATH=/home/linuxbrew/.linuxbrew/bin:$PATH
- export MANPATH=/home/linuxbrew/.linuxbrew/share/man:$MANPATH
- export INFOPATH=/home/linuxbrew/.linuxbrew/share/info:$INFOPATH
-fi
+[ -d "$HOME/bin" ] && export PATH=$HOME/bin:$PATH
export GOPATH=$HOME/src/golang
export PATH=$PATH:$GOPATH/bin
diff --git a/bin/articlesearch b/bin/articlesearch
@@ -4,10 +4,20 @@ set -e
browser=${BROWSER:-firefox}
dir="$HOME/articles"
-choice="$(find "$dir" -type f | sed "s|$dir/||" | dmenu_themed -i -l 10 -p "Search publications:")" || exit 1
+query="$(find "$dir" -type f | sed "s|$dir/||" | dmenu_themed -i -l 10 -p "Search publications:")" || exit 1
-if [ -f "$dir/$choice" ]; then
- xdg-open "$dir/$choice"
+action="$(printf "Open\nAdd citation" | dmenu_themed -i -p "Action:")"
+
+if [ "$action" = "Open" ]; then
+ if [ -f "$dir/$query" ]; then
+ xdg-open "$dir/$query"
+ else
+ $browser "https://scholar.google.com/scholar?q=$query"
+ fi
+elif [ "$action" = "Add citation" ]; then
+ reference="$(scholarref "$query")"
+ echo "$reference" >> "$BIB"
+ notify-send "<b>Added citation</b>$reference"
else
- $browser "https://scholar.google.com/scholar?q=$choice"
+ notify-send --category=error "<b>Action not understood</b>"
fi
diff --git a/bin/getcitation b/bin/getcitation
@@ -69,6 +69,8 @@ function abbreviate_journal_name {
s/Communications/Commun./
s/Geoscience/Geosci./
s/Landforms/Land./
+ s/Science/Sci./
+ s/Annual/Ann./
s/ of / /
s/ and / /
s/ in / /
@@ -93,6 +95,7 @@ function get_citation {
result="$(echo "$result" | format_bibtex_key)"
[ "$fulljournal" = 0 ] && result="$(echo "$result" | abbreviate_journal_name)"
[ "$fullauthor" = 0 ] && result="$(echo "$result" | abbreviate_author_name)"
+ result="$(echo "$result" | sed 's/\t/ /g')"
if [ "$nonewline" = 1 ]; then
echo -en "\n$result"
else