summaryrefslogtreecommitdiff
path: root/paraboladocs
blob: 78e1c0120aba69a47e7ec5f848da2c177a393eeb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# alfplayer
# 2014-12-24
# 
# To be sourced. Provides functions to work with Paraboladocs 
# https://wiki.parabola.nu/Paraboladocs


. 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
}