# alfplayer # 2014-12-24 # # To be sourced. Provides functions to work with Paraboladocs # (http://projects.parabola.nu/paraboladocs.git) . libremessages die2() { echo "Current branch is: $(git branch)" #die "$1" error "$1" return 1 } titlecase() { python -c "from titlecase import titlecase; print(titlecase(\"$1\"));" } load() { eval title="$(sed 's/ /_/g' <<< \"$1\")" if [[ $2 ]] ; then eval title_arch="$(sed 's/ /_/g' <<< \"$2\")" else eval title_arch="$title" fi } load_arch() { #title="$1" if [[ $1 == -t ]] ; then title_arch="$(titlecase "$2")" eval title_arch="$(sed 's/ /_/g' <<< \"$title_arch\")" else eval title_arch="$(sed 's/ /_/g' <<< \"$1\")" fi } show() { echo "Parabola title : $title" echo "Arch title : $title_arch" } unload() { unset title unset titlearch } export title export title_arch diff() { git diff --word-diff arch:"$title_arch" master:"$title" } editdiff() { echo "Checking out master" git checkout master gvimdiff <(git show arch:"$title_arch") "$title" } clipboard_save() { #git show master:"$title" | xsel cat "$title" | xsel } kill_browser() { pkill -f 'iceweasel -P bigscreenparalelo' } compare() { kill_browser iceweasel -P bigscreenparalelo -new-instance 2> /dev/null & i3-msg workspace 14 > /dev/null sleep 0.7 export DESKTOP_STARTUP_ID='' url="https://wiki.parabola.nu" iceweasel -P bigscreenparalelo -remote "openURL($url/index.php?title=$title&action=render,new-tab)" 2> /dev/null & url="https://wiki.archlinux.org" iceweasel -P bigscreenparalelo -remote "openURL($url/index.php?title=$title_arch&action=render,new-window)" 2> /dev/null & } edit() { iceweasel "https://wiki.parabola.nu/index.php?title=$title&action=edit" 2> /dev/null } _get() { if [[ $1 == parabola ]] ; then wiki="ParabolaWiki" branch="master" url="https://wiki.parabola.nu" elif [[ $1 == arch ]] ; then title="$title_arch" wiki="ArchWiki" branch="arch" url="https://wiki.archlinux.org" fi if [[ -e $title ]] ; then msg="update" else msg="add" fi git checkout "$branch" || \ die2 "git checkout \"$branch\" failed" || return 1 curl -s "$url/index.php?title=$title&action=raw" > "$title" || \ die2 "curl failed" || return 1 [[ $(cat "$title") ]] || \ die2 "$wiki page is empty" || return 1 git add "$title" || \ die2 "$wiki git add failed" || return 1 git commit -m "$title: $msg" || \ die2 "$wiki git commit failed" || return 1 } get() { if [[ $1 == parabola ]] ; then _get parabola elif [[ $1 == arch ]] ; then _get arch elif [[ ! $1 ]] ; then _get parabola _get arch fi }