literate-dotfiles/docs/scripts.html

830 lines
58 KiB
HTML

<?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-01-11 sam. 22:19 -->
<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>
<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>
<script type="text/javascript">
/*
@licstart The following is the entire license notice for the
JavaScript code in this tag.
Copyright (C) 2012-2020 Free Software Foundation, Inc.
The JavaScript code in this tag is free software: you can
redistribute it and/or modify it under the terms of the GNU
General Public License (GNU GPL) as published by the Free Software
Foundation, either version 3 of the License, or (at your option)
any later version. The code is distributed WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
As additional permission under GNU GPL version 3 section 7, you
may distribute non-source (e.g., minimized or compacted) forms of
that code without the copy of the GNU GPL normally required by
section 4, provided you include this license notice and a URL
through which recipients can access the Corresponding Source.
@licend The above is the entire license notice
for the JavaScript code in this tag.
*/
<!--/*--><![CDATA[/*><!--*/
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;
}
/*]]>*///-->
</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>
<li><a href="#orgfbe1cfb">Wallpapers</a></li>
<li><a href="#orgf13ea83"><span class="todo TODO">TODO</span> LockScreen</a></li>
<li><a href="#org8650271">Delete first page of PDF</a></li>
<li><a href="#org872b600">Lock / Exit / Suspend / &#x2026;</a></li>
<li><a href="#orgb22aafc"><span class="todo TODO">TODO</span> Copy Figures</a></li>
<li><a href="#org94552bb">NAS</a>
<ul>
<li><a href="#orgf17f358">Mount</a></li>
</ul>
</li>
<li><a href="#org9ec63f3">Buku Git Push</a></li>
<li><a href="#orge80ca70">Icons Unicode</a></li>
<li><a href="#org057a09a">Make GIF</a></li>
<li><a href="#org9c287ad">Org-Capture</a></li>
<li><a href="#orgf8811c6">Download-Audio</a></li>
<li><a href="#org4bf6924">Download-Video</a></li>
<li><a href="#orgfe8be19">Org-Protocol-Capture-HTML</a></li>
<li><a href="#orgc11443d">Pdf Shrink</a></li>
</ul>
</div>
</div>
<div id="outline-container-orgfbe1cfb" class="outline-2">
<h2 id="orgfbe1cfb">Wallpapers</h2>
<div class="outline-text-2" id="text-orgfbe1cfb">
<div class="org-src-container">
<pre class="src src-bash"><span class="org-keyword">while</span> true; <span class="org-keyword">do</span>
nitrogen --set-zoom-fill --random <span class="org-string">".wallpapers"</span>
<span class="org-type">sleep</span> 10m
<span class="org-keyword">done</span>
</pre>
</div>
</div>
</div>
<div id="outline-container-orgf13ea83" class="outline-2">
<h2 id="orgf13ea83"><span class="todo TODO">TODO</span> LockScreen</h2>
<div class="outline-text-2" id="text-orgf13ea83">
<ul class="org-ul">
<li class="off"><code>[&#xa0;]</code> Does not work well with multiple screen</li>
</ul>
<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">
<pre class="src src-bash">i3lock -e -n -i $<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
</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-org8650271" class="outline-2">
<h2 id="org8650271">Delete first page of PDF</h2>
<div class="outline-text-2" id="text-org8650271">
<p>
The requirement is to have <code>pdftk</code> or <code>stapler</code> installed.
</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> -f $<span class="org-highlight-numbers-number">1</span> &amp;&amp; $<span class="org-highlight-numbers-number">1</span> == *.pdf <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-comment-delimiter"># </span><span class="org-comment">Argument if a file</span>
<span class="org-keyword">if </span><span class="org-builtin">type</span> stapler &gt; /dev/null; <span class="org-keyword">then</span>
stapler del <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-highlight-numbers-number">1</span> /tmp/pdftk_out.pdf &amp;&amp; <span class="org-type">mv</span> /tmp/pdftk_out.pdf <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">elif </span><span class="org-builtin">type</span> pdftk &gt; /dev/null; <span class="org-keyword">then</span>
pdftk <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-type">cat</span> 2-end output /tmp/pdftk_out.pdf &amp;&amp; <span class="org-type">mv</span> /tmp/pdftk_out.pdf <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">else</span>
<span class="org-type">echo</span> <span class="org-string">"Neither pdftk nor stapler are installed"</span>
<span class="org-keyword">fi</span>
<span class="org-keyword">fi</span>
</pre>
</div>
</div>
</div>
<div id="outline-container-org872b600" class="outline-2">
<h2 id="org872b600">Lock / Exit / Suspend / &#x2026;</h2>
<div class="outline-text-2" id="text-org872b600">
<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>
<div id="outline-container-orgb22aafc" class="outline-2">
<h2 id="orgb22aafc"><span class="todo TODO">TODO</span> Copy Figures</h2>
<div class="outline-text-2" id="text-orgb22aafc">
<p>
Things to do:
</p>
<ul class="org-ul">
<li class="off"><code>[&#xa0;]</code> Display all the figures at once and ask for confirmation to copy them all</li>
<li class="off"><code>[&#xa0;]</code> Display the not found figures</li>
</ul>
<div class="org-src-container">
<pre class="src src-bash"><span class="org-variable-name">latexpath</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">/Cloud/thesis/latex/ressources/Figures"</span>;
<span class="org-variable-name">figures</span>=<span class="org-sh-quoted-exec">`awk 'match($0, /(fig.*\.(png|svg|pdf))/, a) {print a[1];}' $1 \</span>
<span class="org-sh-quoted-exec"> | awk '{ print gensub(/\s*\]\]\s*\|\s*\[\[\s*\.?\/?/, "\n", "g") }'`</span>;
<span class="org-keyword">for</span> figure<span class="org-keyword"> in</span> $<span class="org-variable-name">figures</span>
<span class="org-keyword">do</span>
<span class="org-variable-name">figurename</span>=<span class="org-sh-quoted-exec">`</span><span class="org-type"><span class="org-sh-quoted-exec">echo</span></span><span class="org-sh-quoted-exec"> $figure | awk 'match($0, /(fig.*\/)(.*\.(png|svg|pdf))/, a) {print a[2];}'`</span>;
<span class="org-keyword">if</span> <span class="org-rainbow-delimiters-depth-1">[</span> -f $<span class="org-variable-name">latexpath</span>/$<span class="org-variable-name">figurename</span> <span class="org-rainbow-delimiters-depth-1">]</span>
<span class="org-keyword">then</span>
<span class="org-variable-name">figurepath</span>=<span class="org-sh-quoted-exec">`</span><span class="org-type"><span class="org-sh-quoted-exec">echo</span></span><span class="org-sh-quoted-exec"> $figure | awk 'match($0, /(fig.*)\/(.*\.(png|svg|pdf))/, a) {print a[1];}'`</span>;
<span class="org-comment-delimiter"># </span><span class="org-type"><span class="org-comment">echo</span></span><span class="org-comment"> $latexpath/$figurename</span>
<span class="org-comment-delimiter"># </span><span class="org-type"><span class="org-comment">echo</span></span><span class="org-comment"> $figurepath/$figurename</span>
<span class="org-type">cp</span> $<span class="org-variable-name">latexpath</span>/$<span class="org-variable-name">figurename</span> $<span class="org-variable-name">figurepath</span>/$<span class="org-variable-name">figurename</span>
<span class="org-comment-delimiter"># </span><span class="org-comment">read -r -p "Are You Sure? [Y/n] " input</span>
<span class="org-comment-delimiter"># </span><span class="org-comment">case $input in</span>
<span class="org-comment-delimiter"># </span><span class="org-comment">[yY][eE][sS]|[yY])</span>
<span class="org-comment-delimiter"># </span><span class="org-type"><span class="org-comment">cp</span></span><span class="org-comment"> $latexpath/$figurename $figurepath/$figurename</span>
<span class="org-comment-delimiter"># </span><span class="org-comment">;;</span>
<span class="org-comment-delimiter"># </span><span class="org-comment">[nN][oO]|[nN])</span>
<span class="org-comment-delimiter"># </span><span class="org-comment">exit 1</span>
<span class="org-comment-delimiter"># </span><span class="org-comment">;;</span>
<span class="org-comment-delimiter"># </span><span class="org-comment">*)</span>
<span class="org-comment-delimiter"># </span><span class="org-type"><span class="org-comment">echo</span></span><span class="org-comment"> "Invalid input..."</span>
<span class="org-comment-delimiter"># </span><span class="org-comment">exit 1</span>
<span class="org-comment-delimiter"># </span><span class="org-comment">;;</span>
<span class="org-comment-delimiter"># </span><span class="org-comment">esac</span>
<span class="org-keyword">fi</span>
<span class="org-keyword">done</span>
</pre>
</div>
</div>
</div>
<div id="outline-container-org94552bb" class="outline-2">
<h2 id="org94552bb">NAS</h2>
<div class="outline-text-2" id="text-org94552bb">
</div>
<div id="outline-container-orgf17f358" class="outline-3">
<h3 id="orgf17f358">Mount</h3>
<div class="outline-text-3" id="text-orgf17f358">
<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>
<span class="org-keyword">if</span> <span class="org-type">sudo</span> -A mount 192.168.1.2:/volume1/Downloads/ /mnt/NAS/; <span class="org-keyword">then</span>
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>
<span class="org-keyword">if</span> <span class="org-type">sudo</span> -A umount /mnt/NAS/; <span class="org-keyword">then</span>
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>
</div>
<div id="outline-container-org9ec63f3" class="outline-2">
<h2 id="org9ec63f3">Buku Git Push</h2>
<div class="outline-text-2" id="text-org9ec63f3">
<div class="org-src-container">
<pre class="src src-bash"><span class="org-type">cd</span> ~/.local/share/buku/
<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-negation-char">!</span> -z $<span class="org-rainbow-delimiters-depth-3">(</span><span class="org-sh-quoted-exec">git</span> status -s bookmarks.db<span class="org-rainbow-delimiters-depth-3">)</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">git</span> add bookmarks.db
<span class="org-type">git</span> commit -m <span class="org-string">"Changed bookmarks - </span><span class="org-string"><span class="org-sh-quoted-exec">$(</span></span><span class="org-sh-quoted-exec">date</span><span class="org-string"><span class="org-sh-quoted-exec"> +%F)</span></span><span class="org-string">"</span>
<span class="org-type">git</span> push
dunstify --replace=<span class="org-highlight-numbers-number">79248</span> <span class="org-string">"Buku Git"</span> <span class="org-string">"Updated"</span>
<span class="org-keyword">exit</span>
<span class="org-keyword">fi</span>
</pre>
</div>
</div>
</div>
<div id="outline-container-orge80ca70" class="outline-2">
<h2 id="orge80ca70">Icons Unicode</h2>
<div class="outline-text-2" id="text-orge80ca70">
<div class="org-src-container">
<pre class="src src-bash"><span class="org-builtin">command</span> -v xclip &gt;/dev/null <span class="org-highlight-numbers-number">2</span>&gt;&amp;<span class="org-highlight-numbers-number">1</span> || <span class="org-rainbow-delimiters-depth-1">{</span> <span class="org-type">echo</span> &gt;&amp;<span class="org-highlight-numbers-number">2</span> <span class="org-string">"I require xclip but it's not installed. Aborting."</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-variable-name">chosen</span>=$<span class="org-rainbow-delimiters-depth-1">(</span><span class="org-sh-quoted-exec">grep</span> -v <span class="org-string">"#"</span> ~/.config/emoji | dmenu -i -l <span class="org-highlight-numbers-number">20</span><span class="org-rainbow-delimiters-depth-1">)</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">chosen</span></span><span class="org-string">"</span> != <span class="org-string">""</span> <span class="org-rainbow-delimiters-depth-1">]</span> || <span class="org-keyword">exit</span>
<span class="org-variable-name">c</span>=$<span class="org-rainbow-delimiters-depth-1">(</span><span class="org-sh-quoted-exec">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">chosen</span></span><span class="org-string">"</span> | sed <span class="org-string">"s/ .*//"</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">c</span></span><span class="org-string">"</span> | tr -d <span class="org-string">'\n'</span> | xclip -selection clipboard
dunstify --replace=<span class="org-highlight-numbers-number">05896</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">c</span></span><span class="org-string">' copied to clipboard."</span> &amp;
</pre>
</div>
</div>
</div>
<div id="outline-container-org057a09a" class="outline-2">
<h2 id="org057a09a">Make GIF</h2>
<div class="outline-text-2" id="text-org057a09a">
<p>
<a href="http://blog.pkh.me/p/21-high-quality-gif-with-ffmpeg.html">http://blog.pkh.me/p/21-high-quality-gif-with-ffmpeg.html</a>
</p>
<div class="org-src-container">
<pre class="src src-bash"><span class="org-variable-name">palette</span>=<span class="org-string">"/tmp/palette.png"</span>
<span class="org-variable-name">filters</span>=<span class="org-string">"fps=15,scale=320:-1:flags=lanczos"</span>
ffmpeg -v warning -i $<span class="org-highlight-numbers-number">1</span> -vf <span class="org-string">"</span><span class="org-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">filters</span></span><span class="org-string">,palettegen"</span> -y $<span class="org-variable-name">palette</span>
ffmpeg -v warning -i $<span class="org-highlight-numbers-number">1</span> -i $<span class="org-variable-name">palette</span> -lavfi <span class="org-string">"</span><span class="org-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">filters</span></span><span class="org-string"> [x]; [x][1:v] paletteuse"</span> -y $<span class="org-highlight-numbers-number">2</span>
</pre>
</div>
</div>
</div>
<div id="outline-container-org9c287ad" class="outline-2">
<h2 id="org9c287ad">Org-Capture</h2>
<div class="outline-text-2" id="text-org9c287ad">
<div class="org-src-container">
<pre class="src src-bash">xclip -o -selection primary | xclip -o -selection clipboard -i
emacsclient -ne <span class="org-string">'(org-capture "" "Q")'</span> &amp;&amp; dunstify <span class="org-string">"Emacs"</span> <span class="org-string">"Text Successfully Captured"</span>
</pre>
</div>
</div>
</div>
<div id="outline-container-orgf8811c6" class="outline-2">
<h2 id="orgf8811c6">Download-Audio</h2>
<div class="outline-text-2" id="text-orgf8811c6">
<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-variable-name">TMUX</span> <span class="org-rainbow-delimiters-depth-1">]</span>; <span class="org-keyword">then</span>
tmux split -v -l <span class="org-highlight-numbers-number">1</span> <span class="org-string">"</span><span class="org-type"><span class="org-string">cd</span></span><span class="org-string"> ~/Downloads/ &amp;&amp; youtube-dl --add-metadata -xic -f bestaudio/best </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> &amp;&amp; tmux select-pane -U
<span class="org-keyword">else</span>
<span class="org-type">cd</span> ~/Downloads/;
setsid nohup youtube-dl --add-metadata -xic -f bestaudio/best $<span class="org-highlight-numbers-number">1</span> &amp;&gt; /dev/null &amp;
<span class="org-keyword">fi</span>
</pre>
</div>
</div>
</div>
<div id="outline-container-org4bf6924" class="outline-2">
<h2 id="org4bf6924">Download-Video</h2>
<div class="outline-text-2" id="text-org4bf6924">
<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-variable-name">TMUX</span> <span class="org-rainbow-delimiters-depth-1">]</span>; <span class="org-keyword">then</span>
tmux split -v -l <span class="org-highlight-numbers-number">1</span> <span class="org-string">"</span><span class="org-type"><span class="org-string">cd</span></span><span class="org-string"> ~/Downloads/ &amp;&amp; youtube-dl --add-metadata -ic </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> &amp;&amp; tmux select-pane -U
<span class="org-keyword">else</span>
<span class="org-type">cd</span> ~/Downloads/;
setsid nohup youtube-dl --add-metadata -ic $<span class="org-highlight-numbers-number">1</span> &amp;&gt; /dev/null &amp;
<span class="org-keyword">fi</span>
</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>
<div id="outline-container-orgc11443d" class="outline-2">
<h2 id="orgc11443d">Pdf Shrink</h2>
<div class="outline-text-2" id="text-orgc11443d">
<div class="org-src-container">
<pre class="src src-bash"><span class="org-function-name">shrink</span> <span class="org-rainbow-delimiters-depth-1">()</span>
<span class="org-rainbow-delimiters-depth-1">{</span>
gs <span class="org-sh-escaped-newline">\</span>
-q -dNOPAUSE -dBATCH -dSAFER <span class="org-sh-escaped-newline">\</span>
-sDEVICE=pdfwrite <span class="org-sh-escaped-newline">\</span>
-dCompatibilityLevel=<span class="org-highlight-numbers-number">1.3</span> <span class="org-sh-escaped-newline">\</span>
-dPDFSETTINGS=/screen <span class="org-sh-escaped-newline">\</span>
-dEmbedAllFonts=true <span class="org-sh-escaped-newline">\</span>
-dSubsetFonts=true <span class="org-sh-escaped-newline">\</span>
-dAutoRotatePages=/None <span class="org-sh-escaped-newline">\</span>
-dColorImageDownsampleType=/Bicubic <span class="org-sh-escaped-newline">\</span>
-dColorImageResolution=$<span class="org-highlight-numbers-number">3</span> <span class="org-sh-escaped-newline">\</span>
-dGrayImageDownsampleType=/Bicubic <span class="org-sh-escaped-newline">\</span>
-dGrayImageResolution=$<span class="org-highlight-numbers-number">3</span> <span class="org-sh-escaped-newline">\</span>
-dMonoImageDownsampleType=/Subsample <span class="org-sh-escaped-newline">\</span>
-dMonoImageResolution=$<span class="org-highlight-numbers-number">3</span> <span class="org-sh-escaped-newline">\</span>
-sOutputFile=<span class="org-string">"</span><span class="org-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">2</span></span><span class="org-string">"</span> <span class="org-sh-escaped-newline">\</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-rainbow-delimiters-depth-1">}</span>
<span class="org-function-name">check_smaller</span> <span class="org-rainbow-delimiters-depth-1">()</span>
<span class="org-rainbow-delimiters-depth-1">{</span>
<span class="org-comment-delimiter"># </span><span class="org-comment">If $1 and $2 are regular files, we can compare file sizes to</span>
<span class="org-comment-delimiter"># </span><span class="org-comment">see if we succeeded in shrinking. If not, we copy $1 over $2:</span>
<span class="org-keyword">if</span> <span class="org-rainbow-delimiters-depth-2">[</span> <span class="org-negation-char">!</span> -f <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> -o <span class="org-negation-char">!</span> -f <span class="org-string">"</span><span class="org-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">2</span></span><span class="org-string">"</span> <span class="org-rainbow-delimiters-depth-2">]</span>; <span class="org-keyword">then</span>
<span class="org-keyword">return</span> <span class="org-highlight-numbers-number">0</span>;
<span class="org-keyword">fi</span>
<span class="org-variable-name">ISIZE</span>=<span class="org-string">"</span><span class="org-string"><span class="org-sh-quoted-exec">$(</span></span><span class="org-sh-quoted-exec">echo</span><span class="org-string"><span class="org-sh-quoted-exec"> $(</span></span><span class="org-sh-quoted-exec">wc</span><span class="org-string"><span class="org-sh-quoted-exec"> -c "</span></span><span class="org-string"><span class="org-constant"><span class="org-sh-quoted-exec">$</span></span></span><span class="org-string"><span class="org-variable-name"><span class="org-sh-quoted-exec">1</span></span></span><span class="org-string"><span class="org-sh-quoted-exec">")</span></span><span class="org-string"> | cut -f1 -d\ )"</span>
<span class="org-variable-name">OSIZE</span>=<span class="org-string">"</span><span class="org-string"><span class="org-sh-quoted-exec">$(</span></span><span class="org-sh-quoted-exec">echo</span><span class="org-string"><span class="org-sh-quoted-exec"> $(</span></span><span class="org-sh-quoted-exec">wc</span><span class="org-string"><span class="org-sh-quoted-exec"> -c "</span></span><span class="org-string"><span class="org-constant"><span class="org-sh-quoted-exec">$</span></span></span><span class="org-string"><span class="org-variable-name"><span class="org-sh-quoted-exec">2</span></span></span><span class="org-string"><span class="org-sh-quoted-exec">")</span></span><span class="org-string"> | cut -f1 -d\ )"</span>
<span class="org-keyword">if</span> <span class="org-rainbow-delimiters-depth-2">[</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">ISIZE</span></span><span class="org-string">"</span> -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">OSIZE</span></span><span class="org-string">"</span> <span class="org-rainbow-delimiters-depth-2">]</span>; <span class="org-keyword">then</span>
<span class="org-type">echo</span> <span class="org-string">"Input smaller than output, doing straight copy"</span> &gt;&amp;<span class="org-highlight-numbers-number">2</span>
<span class="org-type">cp</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-string">"</span><span class="org-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">2</span></span><span class="org-string">"</span>
<span class="org-keyword">fi</span>
<span class="org-rainbow-delimiters-depth-1">}</span>
<span class="org-function-name">usage</span> <span class="org-rainbow-delimiters-depth-1">()</span>
<span class="org-rainbow-delimiters-depth-1">{</span>
<span class="org-type">echo</span> <span class="org-string">"Reduces PDF filesize by lossy recompressing with Ghostscript."</span>
<span class="org-type">echo</span> <span class="org-string">"Not guaranteed to succeed, but usually works."</span>
<span class="org-type">echo</span> <span class="org-string">" Usage: </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"> infile [outfile] [resolution_in_dpi]"</span>
<span class="org-rainbow-delimiters-depth-1">}</span>
<span class="org-variable-name">IFILE</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">Need an input file:</span>
<span class="org-keyword">if</span> <span class="org-rainbow-delimiters-depth-1">[</span> -z <span class="org-string">"</span><span class="org-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">IFILE</span></span><span class="org-string">"</span> <span class="org-rainbow-delimiters-depth-1">]</span>; <span class="org-keyword">then</span>
usage <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>
<span class="org-keyword">exit</span> <span class="org-highlight-numbers-number">1</span>
<span class="org-keyword">fi</span>
<span class="org-comment-delimiter"># </span><span class="org-comment">Output filename defaults to "-" (stdout) unless given:</span>
<span class="org-keyword">if</span> <span class="org-rainbow-delimiters-depth-1">[</span> <span class="org-negation-char">!</span> -z <span class="org-string">"</span><span class="org-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">2</span></span><span class="org-string">"</span> <span class="org-rainbow-delimiters-depth-1">]</span>; <span class="org-keyword">then</span>
<span class="org-variable-name">OFILE</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">2</span></span><span class="org-string">"</span>
<span class="org-keyword">else</span>
<span class="org-variable-name">OFILE</span>=<span class="org-string">"-"</span>
<span class="org-keyword">fi</span>
<span class="org-comment-delimiter"># </span><span class="org-comment">Output resolution defaults to 72 unless given:</span>
<span class="org-keyword">if</span> <span class="org-rainbow-delimiters-depth-1">[</span> <span class="org-negation-char">!</span> -z <span class="org-string">"</span><span class="org-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">3</span></span><span class="org-string">"</span> <span class="org-rainbow-delimiters-depth-1">]</span>; <span class="org-keyword">then</span>
<span class="org-variable-name">res</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">3</span></span><span class="org-string">"</span>
<span class="org-keyword">else</span>
<span class="org-variable-name">res</span>=<span class="org-string">"90"</span>
<span class="org-keyword">fi</span>
shrink <span class="org-string">"</span><span class="org-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">IFILE</span></span><span class="org-string">"</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">OFILE</span></span><span class="org-string">"</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">res</span></span><span class="org-string">"</span> || <span class="org-keyword">exit</span> $<span class="org-variable-name">?</span>
check_smaller <span class="org-string">"</span><span class="org-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">IFILE</span></span><span class="org-string">"</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">OFILE</span></span><span class="org-string">"</span>
</pre>
</div>
</div>
</div>
</div>
<div id="postamble" class="status">
<p class="author">Author: Dehaeze Thomas</p>
<p class="date">Created: 2020-01-11 sam. 22:19</p>
</div>
</body>
</html>