literate-dotfiles/docs/scripts.html

580 lines
34 KiB
HTML
Raw Normal View History

2020-01-11 22:04:45 +01:00
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
2020-04-05 11:30:26 +02:00
<!-- 2020-04-05 dim. 11:29 -->
2020-01-11 22:04:45 +01:00
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Scripts</title>
<meta name="generator" content="Org mode" />
<meta name="author" content="Dehaeze Thomas" />
<style type="text/css">
<!--/*--><![CDATA[/*><!--*/
.title { text-align: center;
margin-bottom: .2em; }
.subtitle { text-align: center;
font-size: medium;
font-weight: bold;
margin-top:0; }
.todo { font-family: monospace; color: red; }
.done { font-family: monospace; color: green; }
.priority { font-family: monospace; color: orange; }
.tag { background-color: #eee; font-family: monospace;
padding: 2px; font-size: 80%; font-weight: normal; }
.timestamp { color: #bebebe; }
.timestamp-kwd { color: #5f9ea0; }
.org-right { margin-left: auto; margin-right: 0px; text-align: right; }
.org-left { margin-left: 0px; margin-right: auto; text-align: left; }
.org-center { margin-left: auto; margin-right: auto; text-align: center; }
.underline { text-decoration: underline; }
#postamble p, #preamble p { font-size: 90%; margin: .2em; }
p.verse { margin-left: 3%; }
pre {
border: 1px solid #ccc;
box-shadow: 3px 3px 3px #eee;
padding: 8pt;
font-family: monospace;
overflow: auto;
margin: 1.2em;
}
pre.src {
position: relative;
overflow: visible;
padding-top: 1.2em;
}
pre.src:before {
display: none;
position: absolute;
background-color: white;
top: -10px;
right: 10px;
padding: 3px;
border: 1px solid black;
}
pre.src:hover:before { display: inline;}
/* Languages per Org manual */
pre.src-asymptote:before { content: 'Asymptote'; }
pre.src-awk:before { content: 'Awk'; }
pre.src-C:before { content: 'C'; }
/* pre.src-C++ doesn't work in CSS */
pre.src-clojure:before { content: 'Clojure'; }
pre.src-css:before { content: 'CSS'; }
pre.src-D:before { content: 'D'; }
pre.src-ditaa:before { content: 'ditaa'; }
pre.src-dot:before { content: 'Graphviz'; }
pre.src-calc:before { content: 'Emacs Calc'; }
pre.src-emacs-lisp:before { content: 'Emacs Lisp'; }
pre.src-fortran:before { content: 'Fortran'; }
pre.src-gnuplot:before { content: 'gnuplot'; }
pre.src-haskell:before { content: 'Haskell'; }
pre.src-hledger:before { content: 'hledger'; }
pre.src-java:before { content: 'Java'; }
pre.src-js:before { content: 'Javascript'; }
pre.src-latex:before { content: 'LaTeX'; }
pre.src-ledger:before { content: 'Ledger'; }
pre.src-lisp:before { content: 'Lisp'; }
pre.src-lilypond:before { content: 'Lilypond'; }
pre.src-lua:before { content: 'Lua'; }
pre.src-matlab:before { content: 'MATLAB'; }
pre.src-mscgen:before { content: 'Mscgen'; }
pre.src-ocaml:before { content: 'Objective Caml'; }
pre.src-octave:before { content: 'Octave'; }
pre.src-org:before { content: 'Org mode'; }
pre.src-oz:before { content: 'OZ'; }
pre.src-plantuml:before { content: 'Plantuml'; }
pre.src-processing:before { content: 'Processing.js'; }
pre.src-python:before { content: 'Python'; }
pre.src-R:before { content: 'R'; }
pre.src-ruby:before { content: 'Ruby'; }
pre.src-sass:before { content: 'Sass'; }
pre.src-scheme:before { content: 'Scheme'; }
pre.src-screen:before { content: 'Gnu Screen'; }
pre.src-sed:before { content: 'Sed'; }
pre.src-sh:before { content: 'shell'; }
pre.src-sql:before { content: 'SQL'; }
pre.src-sqlite:before { content: 'SQLite'; }
/* additional languages in org.el's org-babel-load-languages alist */
pre.src-forth:before { content: 'Forth'; }
pre.src-io:before { content: 'IO'; }
pre.src-J:before { content: 'J'; }
pre.src-makefile:before { content: 'Makefile'; }
pre.src-maxima:before { content: 'Maxima'; }
pre.src-perl:before { content: 'Perl'; }
pre.src-picolisp:before { content: 'Pico Lisp'; }
pre.src-scala:before { content: 'Scala'; }
pre.src-shell:before { content: 'Shell Script'; }
pre.src-ebnf2ps:before { content: 'ebfn2ps'; }
/* additional language identifiers per "defun org-babel-execute"
in ob-*.el */
pre.src-cpp:before { content: 'C++'; }
pre.src-abc:before { content: 'ABC'; }
pre.src-coq:before { content: 'Coq'; }
pre.src-groovy:before { content: 'Groovy'; }
/* additional language identifiers from org-babel-shell-names in
ob-shell.el: ob-shell is the only babel language using a lambda to put
the execution function name together. */
pre.src-bash:before { content: 'bash'; }
pre.src-csh:before { content: 'csh'; }
pre.src-ash:before { content: 'ash'; }
pre.src-dash:before { content: 'dash'; }
pre.src-ksh:before { content: 'ksh'; }
pre.src-mksh:before { content: 'mksh'; }
pre.src-posh:before { content: 'posh'; }
/* Additional Emacs modes also supported by the LaTeX listings package */
pre.src-ada:before { content: 'Ada'; }
pre.src-asm:before { content: 'Assembler'; }
pre.src-caml:before { content: 'Caml'; }
pre.src-delphi:before { content: 'Delphi'; }
pre.src-html:before { content: 'HTML'; }
pre.src-idl:before { content: 'IDL'; }
pre.src-mercury:before { content: 'Mercury'; }
pre.src-metapost:before { content: 'MetaPost'; }
pre.src-modula-2:before { content: 'Modula-2'; }
pre.src-pascal:before { content: 'Pascal'; }
pre.src-ps:before { content: 'PostScript'; }
pre.src-prolog:before { content: 'Prolog'; }
pre.src-simula:before { content: 'Simula'; }
pre.src-tcl:before { content: 'tcl'; }
pre.src-tex:before { content: 'TeX'; }
pre.src-plain-tex:before { content: 'Plain TeX'; }
pre.src-verilog:before { content: 'Verilog'; }
pre.src-vhdl:before { content: 'VHDL'; }
pre.src-xml:before { content: 'XML'; }
pre.src-nxml:before { content: 'XML'; }
/* add a generic configuration mode; LaTeX export needs an additional
(add-to-list 'org-latex-listings-langs '(conf " ")) in .emacs */
pre.src-conf:before { content: 'Configuration File'; }
table { border-collapse:collapse; }
caption.t-above { caption-side: top; }
caption.t-bottom { caption-side: bottom; }
td, th { vertical-align:top; }
th.org-right { text-align: center; }
th.org-left { text-align: center; }
th.org-center { text-align: center; }
td.org-right { text-align: right; }
td.org-left { text-align: left; }
td.org-center { text-align: center; }
dt { font-weight: bold; }
.footpara { display: inline; }
.footdef { margin-bottom: 1em; }
.figure { padding: 1em; }
.figure p { text-align: center; }
.equation-container {
display: table;
text-align: center;
width: 100%;
}
.equation {
vertical-align: middle;
}
.equation-label {
display: table-cell;
text-align: right;
vertical-align: middle;
}
.inlinetask {
padding: 10px;
border: 2px solid gray;
margin: 10px;
background: #ffffcc;
}
#org-div-home-and-up
{ text-align: right; font-size: 70%; white-space: nowrap; }
textarea { overflow-x: auto; }
.linenr { font-size: smaller }
.code-highlighted { background-color: #ffff00; }
.org-info-js_info-navigation { border-style: none; }
#org-info-js_console-label
{ font-size: 10px; font-weight: bold; white-space: nowrap; }
.org-info-js_search-highlight
{ background-color: #ffff00; color: #000000; font-weight: bold; }
.org-svg { width: 90%; }
/*]]>*/-->
</style>
2020-01-11 22:22:46 +01:00
<link rel="stylesheet" type="text/css" href="./css/htmlize.css"/>
<link rel="stylesheet" type="text/css" href="./css/readtheorg.css"/>
<script type="text/javascript" src="./js/jquery.min.js"></script>
<script type="text/javascript" src="./js/bootstrap.min.js"></script>
<script type="text/javascript" src="./js/jquery.stickytableheaders.min.js"></script>
<script type="text/javascript" src="./js/readtheorg.js"></script>
2020-01-11 22:04:45 +01:00
<script type="text/javascript">
2020-04-05 11:30:26 +02:00
// @license magnet:?xt=urn:btih:1f739d935676111cfff4b4693e3816e664797050&amp;dn=gpl-3.0.txt GPL-v3-or-Later
2020-01-11 22:04:45 +01:00
<!--/*--><![CDATA[/*><!--*/
2020-04-05 11:30:26 +02:00
function CodeHighlightOn(elem, id)
{
var target = document.getElementById(id);
if(null != target) {
elem.cacheClassElem = elem.className;
elem.cacheClassTarget = target.className;
target.className = "code-highlighted";
elem.className = "code-highlighted";
}
}
function CodeHighlightOff(elem, id)
{
var target = document.getElementById(id);
if(elem.cacheClassElem)
elem.className = elem.cacheClassElem;
if(elem.cacheClassTarget)
target.className = elem.cacheClassTarget;
}
/*]]>*///-->
// @license-end
2020-01-11 22:04:45 +01:00
</script>
</head>
<body>
<div id="org-div-home-and-up">
<a accesskey="h" href="./index.html"> UP </a>
|
<a accesskey="H" href="./index.html"> HOME </a>
</div><div id="content">
<h1 class="title">Scripts</h1>
<div id="table-of-contents">
<h2>Table of Contents</h2>
<div id="text-table-of-contents">
<ul>
2020-03-01 22:51:16 +01:00
<li><a href="#orgf13ea83">LockScreen</a></li>
2020-04-05 11:30:26 +02:00
<li><a href="#org872b600"><span class="todo TODO">TODO</span> Lock / Exit / Suspend / &#x2026;</a></li>
2020-03-01 22:51:16 +01:00
<li><a href="#org8a282fd">NAS - Mount</a></li>
2020-04-05 11:30:26 +02:00
<li><a href="#orgb5498b2">Download Torrent</a></li>
2020-01-11 22:04:45 +01:00
<li><a href="#orgfe8be19">Org-Protocol-Capture-HTML</a></li>
2020-03-01 22:51:16 +01:00
<li><a href="#orgcd3ccf1">Restart Mopidy</a></li>
2020-01-11 22:04:45 +01:00
</ul>
</div>
</div>
<div id="outline-container-orgf13ea83" class="outline-2">
2020-03-01 22:51:16 +01:00
<h2 id="orgf13ea83">LockScreen</h2>
2020-01-11 22:04:45 +01:00
<div class="outline-text-2" id="text-orgf13ea83">
<p>
First, turn off dunst
</p>
<div class="org-src-container">
<pre class="src src-bash">killall -SIGUSR1 dunst &amp;&amp; <span class="org-type">echo</span> <span class="org-string">"off"</span> &gt; /tmp/dunststatus;
</pre>
</div>
<p>
Turn off the music if it is playing.
</p>
<div class="org-src-container">
<pre class="src src-bash"><span class="org-variable-name">MPC_STATE</span>=$<span class="org-rainbow-delimiters-depth-1">(</span><span class="org-sh-quoted-exec">mpc</span> | sed -n <span class="org-string">'2p'</span> | cut -d <span class="org-string">"["</span> -f2 | cut -d <span class="org-string">"]"</span> -f1<span class="org-rainbow-delimiters-depth-1">)</span>
<span class="org-keyword">if</span> <span class="org-rainbow-delimiters-depth-1">[</span><span class="org-rainbow-delimiters-depth-2">[</span> $<span class="org-variable-name">MPC_STATE</span> == <span class="org-string">"playing"</span> <span class="org-rainbow-delimiters-depth-2">]</span><span class="org-rainbow-delimiters-depth-1">]</span>; <span class="org-keyword">then</span>
mpc pause
<span class="org-keyword">fi</span>
</pre>
</div>
<p>
Then take a screenshot and process it.
</p>
<div class="org-src-container">
<pre class="src src-bash"><span class="org-variable-name">temp_file</span>=<span class="org-string">"/tmp/screen.png"</span>
<span class="org-type">rm</span> -f $<span class="org-variable-name">temp_file</span>
maim $<span class="org-variable-name">temp_file</span>
convert $<span class="org-variable-name">temp_file</span> -scale 10% -scale 1000% $<span class="org-variable-name">temp_file</span>
</pre>
</div>
<p>
Finally, lock the screen using <code>i3lock</code>.
</p>
<div class="org-src-container">
2020-03-01 22:51:16 +01:00
<pre class="src src-bash">i3lock --no-unlock-indicator --ignore-empty-password --nofork --image=$<span class="org-variable-name">temp_file</span> &amp;&amp; killall -SIGUSR2 dunst &amp;&amp; <span class="org-type">echo</span> <span class="org-string">"on"</span> &gt; /tmp/dunststatus
2020-01-11 22:04:45 +01:00
</pre>
</div>
<div class="org-src-container">
<pre class="src src-bash"><span class="org-function-name">revert</span><span class="org-rainbow-delimiters-depth-1">()</span> <span class="org-rainbow-delimiters-depth-1">{</span>
xset dpms <span class="org-highlight-numbers-number">0</span> <span class="org-highlight-numbers-number">0</span> <span class="org-highlight-numbers-number">0</span>
<span class="org-rainbow-delimiters-depth-1">}</span>
<span class="org-keyword">trap</span> revert HUP INT TERM
<span class="org-comment-delimiter"># </span><span class="org-comment">turn off screen after 5 seconds</span>
xset +dpms dpms <span class="org-highlight-numbers-number">5</span> <span class="org-highlight-numbers-number">5</span> <span class="org-highlight-numbers-number">5</span>
<span class="org-comment-delimiter"># </span><span class="org-comment">Parameters</span>
<span class="org-variable-name">temp_file</span>=<span class="org-string">"/tmp/screen.png"</span>
<span class="org-variable-name">icon</span>=<span class="org-string">"</span><span class="org-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">HOME</span></span><span class="org-string">/Pictures/Evil_Rick_Sprite.png"</span>
<span class="org-variable-name">width</span>=<span class="org-highlight-numbers-number">1920</span>
<span class="org-variable-name">height</span>=<span class="org-highlight-numbers-number">1080</span>
<span class="org-variable-name">blur_factor</span>=<span class="org-highlight-numbers-number">6</span>
<span class="org-variable-name">lock_blur_factor</span>=<span class="org-highlight-numbers-number">0</span>
<span class="org-comment-delimiter"># </span><span class="org-comment">Take the screen shot, blur the image and add the icon</span>
ffmpeg -f x11grab -video_size <span class="org-string">"</span><span class="org-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">{width}</span></span><span class="org-string">x</span><span class="org-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">{height}</span></span><span class="org-string">"</span> -y -i $<span class="org-variable-name">DISPLAY</span> -i $<span class="org-variable-name">icon</span> -filter_complex <span class="org-string">"boxblur=</span><span class="org-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">blur_factor</span></span><span class="org-string">:</span><span class="org-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">blur_factor</span></span><span class="org-string">,overlay=(main_w-overlay_w)/2:(main_h-overlay_h)/2,boxblur=</span><span class="org-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">lock_blur_factor</span></span><span class="org-string">:</span><span class="org-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">lock_blur_factor</span></span><span class="org-string">"</span> -vframes <span class="org-highlight-numbers-number">1</span> $<span class="org-variable-name">temp_file</span>
<span class="org-comment-delimiter"># </span><span class="org-comment">Alternative</span>
<span class="org-comment-delimiter"># </span><span class="org-comment">maim -d 1 $temp_file</span>
<span class="org-comment-delimiter"># </span><span class="org-comment">convert -blur 0x8 $temp_file $temp_file</span>
<span class="org-comment-delimiter"># </span><span class="org-comment">convert -composite $temp_file $icon -gravity South -geometry -20x1200 $temp_file</span>
<span class="org-comment-delimiter"># </span><span class="org-comment">Lock the screen with the image</span>
i3lock --no-unlock-indicator --ignore-empty-password --show-failed-attempts --nofork --image=$<span class="org-variable-name">temp_file</span>
<span class="org-comment-delimiter"># </span><span class="org-comment">Remove the screenshot</span>
<span class="org-type">rm</span> $<span class="org-variable-name">temp_file</span>
<span class="org-comment-delimiter"># </span><span class="org-comment">Don't turn off screen when back from lock</span>
revert
</pre>
</div>
</div>
</div>
<div id="outline-container-org872b600" class="outline-2">
2020-04-05 11:30:26 +02:00
<h2 id="org872b600"><span class="todo TODO">TODO</span> Lock / Exit / Suspend / &#x2026;</h2>
2020-01-11 22:04:45 +01:00
<div class="outline-text-2" id="text-org872b600">
2020-04-05 11:30:26 +02:00
<ul class="org-ul">
<li class="off"><code>[&#xa0;]</code> Seems duplicated with <a href="binaries.html#org1ce653d"><code>i3exit</code> - Manage lock, suspend, reboot, &#x2026;</a></li>
</ul>
2020-01-11 22:04:45 +01:00
<div class="org-src-container">
<pre class="src src-bash"><span class="org-variable-name">option</span>=$<span class="org-rainbow-delimiters-depth-1">(</span><span class="org-sh-quoted-exec">echo</span> -e <span class="org-string">"Lock\nExit\nLogout\nSuspend\nHibernate\nReboot\nShutdown"</span> | rofi -i -dmenu<span class="org-rainbow-delimiters-depth-1">)</span>
<span class="org-keyword">case</span> <span class="org-string">"</span><span class="org-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">option</span></span><span class="org-string">"</span><span class="org-keyword"> in</span>
<span class="org-string">"Lock"</span>)
i3exit lock ;;
<span class="org-string">"Exit"</span>)
i3exit switch_user ;;
<span class="org-string">"Logout"</span>)
i3exit logout ;;
<span class="org-string">"Suspend"</span>)
i3exit suspend ;;
<span class="org-string">"Hibernate"</span>)
i3exit hibernate ;;
<span class="org-string">"Reboot"</span>)
i3exit reboot ;;
<span class="org-string">"Shutdown"</span>)
i3exit shutdown ;;
<span class="org-keyword">esac</span>
</pre>
</div>
</div>
</div>
2020-03-01 22:51:16 +01:00
<div id="outline-container-org8a282fd" class="outline-2">
<h2 id="org8a282fd">NAS - Mount</h2>
<div class="outline-text-2" id="text-org8a282fd">
2020-04-05 11:30:26 +02:00
<p>
As an alternative, <code>sshfs</code> can be used:
</p>
<div class="org-src-container">
<pre class="src src-bash">sshfs -o allow_other,default_permissions nas:/Data ~/mnt/NAS
</pre>
</div>
2020-01-11 22:04:45 +01:00
<div class="org-src-container">
<pre class="src src-bash"><span class="org-keyword">if</span> <span class="org-rainbow-delimiters-depth-1">[</span> $<span class="org-highlight-numbers-number">1</span> == <span class="org-string">"mount"</span> <span class="org-rainbow-delimiters-depth-1">]</span>; <span class="org-keyword">then</span>
2020-04-05 11:30:26 +02:00
<span class="org-keyword">if</span> mount /home/thomas/mnt/NAS/; <span class="org-keyword">then</span>
2020-01-11 22:04:45 +01:00
dunstify --replace=<span class="org-highlight-numbers-number">58249</span> <span class="org-string">'NAS'</span> <span class="org-string">'Successfully mounted'</span>
<span class="org-keyword">else</span>
dunstify --replace=<span class="org-highlight-numbers-number">58249</span> <span class="org-string">'NAS'</span> <span class="org-string">'Error while mounted'</span>
<span class="org-keyword">fi</span>
<span class="org-keyword">elif</span> <span class="org-rainbow-delimiters-depth-1">[</span> $<span class="org-highlight-numbers-number">1</span> == <span class="org-string">"umount"</span> <span class="org-rainbow-delimiters-depth-1">]</span>; <span class="org-keyword">then</span>
2020-04-05 11:30:26 +02:00
<span class="org-keyword">if</span> umount /home/thomas/mnt/NAS/; <span class="org-keyword">then</span>
2020-01-11 22:04:45 +01:00
dunstify --replace=<span class="org-highlight-numbers-number">58249</span> <span class="org-string">'NAS'</span> <span class="org-string">'Successfully unmounted'</span>
<span class="org-keyword">else</span>
dunstify --replace=<span class="org-highlight-numbers-number">58249</span> <span class="org-string">'NAS'</span> <span class="org-string">'Error while unmounted'</span>
<span class="org-keyword">fi</span>
<span class="org-keyword">fi</span>
</pre>
</div>
</div>
</div>
2020-04-05 11:30:26 +02:00
<div id="outline-container-orgb5498b2" class="outline-2">
<h2 id="orgb5498b2">Download Torrent</h2>
<div class="outline-text-2" id="text-orgb5498b2">
2020-01-11 22:04:45 +01:00
<div class="org-src-container">
2020-04-05 11:30:26 +02:00
<pre class="src src-bash">transmission-remote 82.64.103.2:9091 --auth tdehaeze:$<span class="org-rainbow-delimiters-depth-1">(</span><span class="org-sh-quoted-exec">pass</span> nas/transmission | sed -n 1p<span class="org-rainbow-delimiters-depth-1">)</span> -a $<span class="org-highlight-numbers-number">1</span> &amp;&amp; <span class="org-sh-escaped-newline">\</span>
dunstify <span class="org-string">'Torrent'</span> <span class="org-string">'Successfully added'</span> || <span class="org-sh-escaped-newline">\</span>
dunstify <span class="org-string">'Torrent'</span> <span class="org-string">'Error'</span>
2020-01-11 22:04:45 +01:00
</pre>
</div>
</div>
</div>
<div id="outline-container-orgfe8be19" class="outline-2">
<h2 id="orgfe8be19">Org-Protocol-Capture-HTML</h2>
<div class="outline-text-2" id="text-orgfe8be19">
<p>
Defaults
</p>
<div class="org-src-container">
<pre class="src src-bash"><span class="org-variable-name">heading</span>=<span class="org-string">"link"</span>
<span class="org-variable-name">template</span>=<span class="org-string">"pu"</span>
<span class="org-variable-name">url</span>=<span class="org-string">"https://google.com/"</span>
</pre>
</div>
<p>
Functions
</p>
<div class="org-src-container">
<pre class="src src-bash"><span class="org-keyword">function</span> <span class="org-function-name">debug</span> <span class="org-rainbow-delimiters-depth-1">{</span>
<span class="org-keyword">if</span> <span class="org-rainbow-delimiters-depth-2">[</span><span class="org-rainbow-delimiters-depth-3">[</span> -n $<span class="org-variable-name">debug</span> <span class="org-rainbow-delimiters-depth-3">]</span><span class="org-rainbow-delimiters-depth-2">]</span>
<span class="org-keyword">then</span>
<span class="org-keyword">function</span> <span class="org-function-name">debug</span> <span class="org-rainbow-delimiters-depth-2">{</span>
<span class="org-type">echo</span> <span class="org-string">"DEBUG: </span><span class="org-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">@</span></span><span class="org-string">"</span> &gt;&amp;<span class="org-highlight-numbers-number">2</span>
<span class="org-rainbow-delimiters-depth-2">}</span>
debug <span class="org-string">"</span><span class="org-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">@</span></span><span class="org-string">"</span>
<span class="org-keyword">else</span>
<span class="org-keyword">function</span> <span class="org-function-name">debug</span> <span class="org-rainbow-delimiters-depth-2">{</span>
true
<span class="org-rainbow-delimiters-depth-2">}</span>
<span class="org-keyword">fi</span>
<span class="org-rainbow-delimiters-depth-1">}</span>
<span class="org-keyword">function</span> <span class="org-function-name">die</span> <span class="org-rainbow-delimiters-depth-1">{</span>
<span class="org-type">echo</span> <span class="org-string">"</span><span class="org-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">@</span></span><span class="org-string">"</span> &gt;&amp;<span class="org-highlight-numbers-number">2</span>
<span class="org-keyword">exit</span> <span class="org-highlight-numbers-number">1</span>
<span class="org-rainbow-delimiters-depth-1">}</span>
<span class="org-keyword">function</span> <span class="org-function-name">urlencode</span> <span class="org-rainbow-delimiters-depth-1">{</span>
python -c <span class="org-string">"</span>
<span class="org-string">from __future__ import print_function</span>
<span class="org-string">try:</span>
<span class="org-string"> from urllib import quote # Python 2</span>
<span class="org-string">except ImportError:</span>
<span class="org-string"> from urllib.parse import quote # Python 3</span>
<span class="org-string">import sys</span>
<span class="org-string">print(quote(sys.stdin.read()[:-1], safe=''))"</span>
<span class="org-rainbow-delimiters-depth-1">}</span>
</pre>
</div>
<p>
Documentation
</p>
<div class="org-src-container">
<pre class="src src-bash"><span class="org-keyword">function</span> <span class="org-function-name">usage</span> <span class="org-rainbow-delimiters-depth-1">{</span>
<span class="org-type">cat</span> &lt;&lt;EOF
<span class="org-sh-heredoc">$0 [OPTIONS] [HTML]</span>
<span class="org-sh-heredoc">html | $0 [OPTIONS]</span>
<span class="org-sh-heredoc">Send HTML to Emacs through org-protocol, passing it through Pandoc to</span>
<span class="org-sh-heredoc">convert HTML to Org-mode. HTML may be passed as an argument or</span>
<span class="org-sh-heredoc">through STDIN. If only URL is given, it will be downloaded and its</span>
<span class="org-sh-heredoc">contents used.</span>
<span class="org-sh-heredoc">Options:</span>
<span class="org-sh-heredoc"> -h, --heading HEADING Heading</span>
<span class="org-sh-heredoc"> -t, --template TEMPLATE org-capture template key (default: pu)</span>
<span class="org-sh-heredoc"> -u, --url URL URL</span>
<span class="org-sh-heredoc"> --debug Print debug info</span>
<span class="org-sh-heredoc"> --help I need somebody!</span>
<span class="org-sh-heredoc">EOF</span>
<span class="org-rainbow-delimiters-depth-1">}</span>
</pre>
</div>
<p>
Arguments
</p>
<div class="org-src-container">
<pre class="src src-bash"><span class="org-variable-name">args</span>=$<span class="org-rainbow-delimiters-depth-1">(</span><span class="org-sh-quoted-exec">getopt</span> -n <span class="org-string">"</span><span class="org-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">0</span></span><span class="org-string">"</span> -o dh:rt:u: -l debug,help,heading:,template:,url: -- <span class="org-string">"</span><span class="org-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">@</span></span><span class="org-string">"</span><span class="org-rainbow-delimiters-depth-1">)</span> <span class="org-sh-escaped-newline">\</span>
|| die <span class="org-string">"Unable to parse args. Is getopt installed?"</span>
<span class="org-builtin">eval</span> set -- <span class="org-string">"</span><span class="org-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">args</span></span><span class="org-string">"</span>
<span class="org-keyword">while</span> true
<span class="org-keyword">do</span>
<span class="org-keyword">case</span> <span class="org-string">"</span><span class="org-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">1</span></span><span class="org-string">"</span><span class="org-keyword"> in</span>
-d|--debug)
<span class="org-variable-name">debug</span>=true
debug <span class="org-string">"Debugging on"</span>
;;
--help)
usage
<span class="org-keyword">exit</span>
;;
-h|--heading)
<span class="org-builtin">shift</span>
<span class="org-variable-name">heading</span>=<span class="org-string">"</span><span class="org-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">1</span></span><span class="org-string">"</span>
;;
-t|--template)
<span class="org-builtin">shift</span>
<span class="org-variable-name">template</span>=<span class="org-string">"</span><span class="org-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">1</span></span><span class="org-string">"</span>
;;
-u|--url)
<span class="org-builtin">shift</span>
<span class="org-variable-name">url</span>=<span class="org-string">"</span><span class="org-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">1</span></span><span class="org-string">"</span>
;;
--)
<span class="org-comment-delimiter"># </span><span class="org-comment">Remaining args</span>
<span class="org-builtin">shift</span>
<span class="org-variable-name">rest</span>=<span class="org-rainbow-delimiters-depth-1">(</span><span class="org-string">"</span><span class="org-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">@</span></span><span class="org-string">"</span><span class="org-rainbow-delimiters-depth-1">)</span>
<span class="org-keyword">break</span>
;;
<span class="org-keyword">esac</span>
<span class="org-builtin">shift</span>
<span class="org-keyword">done</span>
debug <span class="org-string">"ARGS: </span><span class="org-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">args</span></span><span class="org-string">"</span>
debug <span class="org-string">"Remaining args: </span><span class="org-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">{rest[@]}</span></span><span class="org-string">"</span>
</pre>
</div>
<p>
Get HTML
</p>
<div class="org-src-container">
<pre class="src src-bash"><span class="org-keyword">if</span> <span class="org-rainbow-delimiters-depth-1">[</span><span class="org-rainbow-delimiters-depth-2">[</span> -n $<span class="org-variable-name">@</span> <span class="org-rainbow-delimiters-depth-2">]</span><span class="org-rainbow-delimiters-depth-1">]</span>
<span class="org-keyword">then</span>
debug <span class="org-string">"Text from args"</span>
<span class="org-variable-name">body</span>=<span class="org-string">"</span><span class="org-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">@</span></span><span class="org-string">"</span>
<span class="org-keyword">fi</span>
</pre>
</div>
<p>
URL-encode
</p>
<div class="org-src-container">
<pre class="src src-bash"><span class="org-variable-name">heading</span>=$<span class="org-rainbow-delimiters-depth-1">(</span><span class="org-sh-quoted-exec">urlencode</span> &lt;&lt;&lt;<span class="org-string">"</span><span class="org-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">heading</span></span><span class="org-string">"</span><span class="org-rainbow-delimiters-depth-1">)</span> || die <span class="org-string">"Unable to urlencode heading."</span>
<span class="org-variable-name">url</span>=$<span class="org-rainbow-delimiters-depth-1">(</span><span class="org-sh-quoted-exec">urlencode</span> &lt;&lt;&lt;<span class="org-string">"</span><span class="org-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">url</span></span><span class="org-string">"</span><span class="org-rainbow-delimiters-depth-1">)</span> || die <span class="org-string">"Unable to urlencode URL."</span>
<span class="org-variable-name">body</span>=$<span class="org-rainbow-delimiters-depth-1">(</span><span class="org-sh-quoted-exec">urlencode</span> &lt;&lt;&lt;<span class="org-string">"</span><span class="org-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">body</span></span><span class="org-string">"</span><span class="org-rainbow-delimiters-depth-1">)</span> || die <span class="org-string">"Unable to urlencode text."</span>
</pre>
</div>
<p>
Send to Emacs
</p>
<div class="org-src-container">
<pre class="src src-bash">emacsclient <span class="org-string">"org-protocol://capture?template=</span><span class="org-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">template</span></span><span class="org-string">&amp;url=</span><span class="org-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">url</span></span><span class="org-string">&amp;title=</span><span class="org-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">heading</span></span><span class="org-string">&amp;body=</span><span class="org-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">body</span></span><span class="org-string">"</span>
</pre>
</div>
</div>
</div>
2020-03-01 22:51:16 +01:00
<div id="outline-container-orgcd3ccf1" class="outline-2">
<h2 id="orgcd3ccf1">Restart Mopidy</h2>
<div class="outline-text-2" id="text-orgcd3ccf1">
<div class="org-src-container">
<pre class="src src-bash"><span class="org-variable-name">pids</span>=<span class="org-rainbow-delimiters-depth-1">(</span> $<span class="org-rainbow-delimiters-depth-2">(</span><span class="org-sh-quoted-exec">pgrep</span> -f mopidy<span class="org-rainbow-delimiters-depth-2">)</span> <span class="org-rainbow-delimiters-depth-1">)</span>
2020-01-11 22:04:45 +01:00
2020-03-01 22:51:16 +01:00
<span class="org-keyword">for</span> pid<span class="org-keyword"> in</span> <span class="org-string">"</span><span class="org-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">{pids[@]}</span></span><span class="org-string">"</span>; <span class="org-keyword">do</span>
<span class="org-keyword">if</span> <span class="org-rainbow-delimiters-depth-1">[</span><span class="org-rainbow-delimiters-depth-2">[</span> $<span class="org-variable-name">pid</span> != $<span class="org-variable-name">$</span> <span class="org-rainbow-delimiters-depth-2">]</span><span class="org-rainbow-delimiters-depth-1">]</span>; <span class="org-keyword">then</span>
<span class="org-type">kill</span> <span class="org-string">"</span><span class="org-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">pid</span></span><span class="org-string">"</span>
<span class="org-keyword">fi</span>
<span class="org-keyword">done</span>
2020-01-11 22:04:45 +01:00
2020-03-01 22:51:16 +01:00
<span class="org-type">echo</span> <span class="org-string">"Killed mopidy."</span>
<span class="org-type">echo</span> <span class="org-string">"Restarting mopidy..."</span>
mopidy --config ~/.config/mopidy/mopidy.conf &gt;/dev/null <span class="org-highlight-numbers-number">2</span>&gt;&amp;<span class="org-highlight-numbers-number">1</span> &amp;
<span class="org-type">echo</span> <span class="org-string">"Done"</span>
2020-01-11 22:04:45 +01:00
</pre>
</div>
</div>
</div>
</div>
<div id="postamble" class="status">
<p class="author">Author: Dehaeze Thomas</p>
2020-04-05 11:30:26 +02:00
<p class="date">Created: 2020-04-05 dim. 11:29</p>
2020-01-11 22:04:45 +01:00
</div>
</body>
</html>