literate-dotfiles/docs/binaries.html

1744 lines
173 KiB
HTML
Raw Permalink Normal View History

2020-01-11 22:04:45 +01:00
<?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>
2022-05-09 10:05:23 +02:00
<!-- 2022-05-09 lun. 10:04 -->
2020-01-11 22:04:45 +01:00
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>Binaries</title>
<meta name="author" content="Dehaeze Thomas" />
2021-04-25 19:10:57 +02:00
<meta name="generator" content="Org Mode" />
2021-01-01 20:12:34 +01:00
<link rel="stylesheet" type="text/css" href="./dist/style.css"/>
<script type="text/javascript" src="./dist/script.js"></script>
2020-01-11 22:04:45 +01:00
</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>
2021-10-25 14:37:10 +02:00
</div><div id="content" class="content">
2020-01-11 22:04:45 +01:00
<h1 class="title">Binaries</h1>
2021-10-25 14:37:10 +02:00
<div id="table-of-contents" role="doc-toc">
2020-01-11 22:04:45 +01:00
<h2>Table of Contents</h2>
2021-10-25 14:37:10 +02:00
<div id="text-table-of-contents" role="doc-toc">
2020-01-11 22:04:45 +01:00
<ul>
2021-01-01 20:12:34 +01:00
<li><a href="#dmenumount"><code>dmenumount</code> - Mount USB and Android</a></li>
<li><a href="#dmenuumount"><code>dmenuumount</code> - Unmount USB and Android devices</a></li>
2021-01-08 01:43:48 +01:00
<li><a href="#dmenukill"><code>dmenukill</code> - Kill program using Dmenu</a></li>
2021-01-01 20:12:34 +01:00
<li><a href="#nordvpn-toggle"><code>nordvpn-toggle</code> - Connect to VPN using NordVPN</a></li>
<li><a href="#i3exit"><code>i3exit</code> - Manage lock, suspend, reboot, &#x2026;</a></li>
<li><a href="#askpass-rofi"><code>askpass-rofi</code> - GUI prompt for passwords</a></li>
2022-05-09 10:05:23 +02:00
<li><a href="#get-pass"><code>get-pass</code> - Get Stored Password</a></li>
2021-01-01 20:12:34 +01:00
<li><a href="#screenshot"><code>screenshot</code> - Take Screenshot</a></li>
<li><a href="#network-toggle"><code>network-toggle</code> - Toggle Network</a></li>
<li><a href="#make-gif"><code>make-gif</code> - Convert an <code>MP4</code> video to <code>GIF</code></a></li>
<li><a href="#yt-audio"><code>yt-audio</code> - Download-Audio from youtube</a></li>
<li><a href="#yt-video"><code>yt-video</code> - Download-Video from youtube</a></li>
<li><a href="#setbg"><code>setbg</code> - Set Background</a></li>
<li><a href="#insert-unicode"><code>insert-unicode</code> - Insert Unicode Icon</a></li>
<li><a href="#insert-nerd-fonts"><code>insert-nerd-fonts</code> - Insert Nerd Font Icon</a></li>
2021-10-25 14:37:10 +02:00
<li><a href="#linkhandler"><code>linkhandler</code> - Open any URL with Default application</a></li>
<li><a href="#filehandler"><code>open</code> - Open any file using <code>rifle</code></a></li>
2021-01-01 20:12:34 +01:00
<li><a href="#lockscreen"><code>lockscreen</code> - Lock Screen</a></li>
<li><a href="#mopidy-restart"><code>mopidy-restart</code> - Restart Mopidy</a></li>
<li><a href="#upload"><code>upload</code> - Upload Script</a></li>
<li><a href="#weather"><code>weather</code> - Display Weather in terminal</a></li>
<li><a href="#pdf2bib"><code>pdf2bib</code> - Extract bibtex entry from PDF file</a></li>
<li><a href="#pdf2png"><code>pdf2png</code> - Convert a PDF to PNG</a></li>
2021-10-25 14:37:10 +02:00
<li><a href="#convert-file"><code>convert-file</code> - Convert any file to another filetype</a>
<ul>
2022-05-09 10:05:23 +02:00
<li><a href="#org85b93ef">Get basic information about the file</a></li>
<li><a href="#org0dbfc5e">SVG files</a>
2021-10-25 14:37:10 +02:00
<ul>
2022-05-09 10:05:23 +02:00
<li><a href="#org9ba2b34">SVG to PNG</a></li>
<li><a href="#org9fbf9f2">SVG to PDF</a></li>
<li><a href="#org9abaf53">Main function</a></li>
2021-10-25 14:37:10 +02:00
</ul>
</li>
2022-05-09 10:05:23 +02:00
<li><a href="#org2d81394">PDF files</a>
2021-10-25 14:37:10 +02:00
<ul>
2022-05-09 10:05:23 +02:00
<li><a href="#orgaa8a2c8">PDF to PNG</a></li>
<li><a href="#org353ac60">PDF to SVG</a></li>
<li><a href="#orge2a8819">PDF Reduce Size</a></li>
<li><a href="#org2439e3d">PDF Trim</a></li>
<li><a href="#org5cb9ddc">PDF Extract Pages</a></li>
<li><a href="#org6856d02">Delete First Page</a></li>
<li><a href="#org2fe9680">Remove Annotations</a></li>
<li><a href="#orgde9537c">Main function</a></li>
2021-10-25 14:37:10 +02:00
</ul>
</li>
2022-05-09 10:05:23 +02:00
<li><a href="#org378402e">DVI files</a>
2021-10-25 14:37:10 +02:00
<ul>
2022-05-09 10:05:23 +02:00
<li><a href="#orgbc5f1ef">DVI to PNG</a></li>
<li><a href="#org19c6581">DVI to SVG</a></li>
<li><a href="#org8daeb8f">Main function</a></li>
2021-10-25 14:37:10 +02:00
</ul>
</li>
2022-05-09 10:05:23 +02:00
<li><a href="#orgf8bdda8">DOCX/PTTX files</a>
2021-10-25 14:37:10 +02:00
<ul>
2022-05-09 10:05:23 +02:00
<li><a href="#org1bbbf82">DOC to PDF</a></li>
<li><a href="#orgdf2de45">Main function</a></li>
2021-10-25 14:37:10 +02:00
</ul>
</li>
2022-05-09 10:05:23 +02:00
<li><a href="#org36b178e">GIF files</a>
2021-10-25 14:37:10 +02:00
<ul>
2022-05-09 10:05:23 +02:00
<li><a href="#org1e73b8e">GIF to PNG</a></li>
<li><a href="#org8e1759c">Main function</a></li>
2021-10-25 14:37:10 +02:00
</ul>
</li>
2022-05-09 10:05:23 +02:00
<li><a href="#org2554add">PNG files</a>
2021-10-25 14:37:10 +02:00
<ul>
2022-05-09 10:05:23 +02:00
<li><a href="#org82d3665">PNG to PDF</a></li>
<li><a href="#org60a4f5d">PNG to JPG</a></li>
<li><a href="#org7f202da">PNG Trim</a></li>
<li><a href="#orgedb389b">PNG Resize</a></li>
<li><a href="#orgfc606d5">Main function</a></li>
2021-10-25 14:37:10 +02:00
</ul>
</li>
2022-05-09 10:05:23 +02:00
<li><a href="#orgfa3de5c">JPG files</a>
2021-10-25 14:37:10 +02:00
<ul>
2022-05-09 10:05:23 +02:00
<li><a href="#orgfb74bc5">JPG to PDF</a></li>
<li><a href="#orgb459566">JPG Resize</a></li>
<li><a href="#orgc99bd0b">Main function</a></li>
2021-10-25 14:37:10 +02:00
</ul>
</li>
2022-05-09 10:05:23 +02:00
<li><a href="#org1ce8f02">MP4 files</a>
2021-10-25 14:37:10 +02:00
<ul>
2022-05-09 10:05:23 +02:00
<li><a href="#orgfce3450">MP4 to GIF</a></li>
<li><a href="#org1ef5d98">Main function</a></li>
2021-10-25 14:37:10 +02:00
</ul>
</li>
2022-05-09 10:05:23 +02:00
<li><a href="#orgd348c43">Case statement</a></li>
</ul>
</li>
<li><a href="#preview-file"><code>preview-file</code> - Preview any file</a>
<ul>
<li><a href="#orgf5dc56d">Get basic information about the file</a></li>
<li><a href="#org388aa4c">SVG files</a></li>
<li><a href="#orga4584da">DOCX files</a></li>
<li><a href="#org4a60199">Case statement</a></li>
2021-10-25 14:37:10 +02:00
</ul>
</li>
2021-01-01 20:12:34 +01:00
<li><a href="#pdf-shrink"><code>pdf-shrink</code> - Pdf Shrink</a></li>
<li><a href="#pdf-delete-annotations"><code>pdf-delete-annotations</code> - Delete Annotations from PDFs</a></li>
<li><a href="#pdf-delete-first-page"><code>pdf-delete-first-page</code> - Delete first page of PDF</a></li>
<li><a href="#rofi-calc"><code>rofi-calc</code> - Simple Calculation using Rofi</a></li>
<li><a href="#pass-gen"><code>pass-gen</code> - Generate Random Alphanumeric Password</a></li>
<li><a href="#sxhkd-help"><code>sxhkd-help</code> - List of keybindings using Rofi</a></li>
2020-01-11 22:04:45 +01:00
</ul>
</div>
</div>
2021-01-01 20:12:34 +01:00
<div id="outline-container-dmenumount" class="outline-2">
<h2 id="dmenumount"><code>dmenumount</code> - Mount USB and Android</h2>
<div class="outline-text-2" id="text-dmenumount">
2020-11-03 16:27:09 +01:00
<p>
Script taken from Luke Smith.
</p>
<div class="org-src-container">
<pre class="src src-bash"><span class="org-function-name">getmount</span><span class="org-rainbow-delimiters-depth-1">()</span> <span class="org-rainbow-delimiters-depth-1">{</span> <span class="org-sh-escaped-newline">\</span>
<span class="org-rainbow-delimiters-depth-2">[</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">chosen</span></span><span class="org-string">"</span> <span class="org-rainbow-delimiters-depth-2">]</span> &amp;&amp; <span class="org-keyword">exit</span> <span class="org-highlight-numbers-number">1</span>
<span class="org-comment-delimiter"># </span><span class="org-comment">shellcheck disable=SC2086</span>
<span class="org-variable-name">mp</span>=<span class="org-string">"</span><span class="org-string"><span class="org-sh-quoted-exec">$(</span></span><span class="org-sh-quoted-exec">find</span><span class="org-string"><span class="org-sh-quoted-exec"> </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"> 2&gt;/dev/null | dmenu -i -p "Type in mount point.")</span></span><span class="org-string">"</span> || <span class="org-keyword">exit</span> <span class="org-highlight-numbers-number">1</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">mp</span></span><span class="org-string">"</span> = <span class="org-string">""</span> <span class="org-rainbow-delimiters-depth-2">]</span> &amp;&amp; <span class="org-keyword">exit</span> <span class="org-highlight-numbers-number">1</span>
<span class="org-keyword">if</span> <span class="org-rainbow-delimiters-depth-2">[</span> <span class="org-negation-char">!</span> -d <span class="org-string">"</span><span class="org-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">mp</span></span><span class="org-string">"</span> <span class="org-rainbow-delimiters-depth-2">]</span>; <span class="org-keyword">then</span>
<span class="org-variable-name">mkdiryn</span>=$<span class="org-rainbow-delimiters-depth-2">(</span><span class="org-sh-quoted-exec">printf</span> <span class="org-string">"No\\nYes"</span> | dmenu -i -p <span class="org-string">"</span><span class="org-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">mp</span></span><span class="org-string"> does not exist. Create it?"</span><span class="org-rainbow-delimiters-depth-2">)</span> || <span class="org-keyword">exit</span> <span class="org-highlight-numbers-number">1</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">mkdiryn</span></span><span class="org-string">"</span> = <span class="org-string">"Yes"</span> <span class="org-rainbow-delimiters-depth-2">]</span> &amp;&amp; <span class="org-rainbow-delimiters-depth-2">(</span><span class="org-type">mkdir</span> -p <span class="org-string">"</span><span class="org-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">mp</span></span><span class="org-string">"</span> || <span class="org-type">sudo</span> -A <span class="org-type">mkdir</span> -p <span class="org-string">"</span><span class="org-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">mp</span></span><span class="org-string">"</span><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-function-name">mountusb</span><span class="org-rainbow-delimiters-depth-1">()</span> <span class="org-rainbow-delimiters-depth-1">{</span> <span class="org-sh-escaped-newline">\</span>
<span class="org-variable-name">chosen</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-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">usbdrives</span></span></span><span class="org-string"><span class="org-sh-quoted-exec">" | dmenu -i -p "Mount which drive?")</span></span><span class="org-string">"</span> || <span class="org-keyword">exit</span> <span class="org-highlight-numbers-number">1</span>
<span class="org-variable-name">chosen</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-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">chosen</span></span></span><span class="org-string"><span class="org-sh-quoted-exec">" | awk '{print </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">"</span>
<span class="org-type">sudo</span> -A mount <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-highlight-numbers-number">2</span>&gt;/dev/null &amp;&amp; notify-send <span class="org-string">"&#128187; USB mounting"</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"> mounted."</span> &amp;&amp; <span class="org-keyword">exit</span> <span class="org-highlight-numbers-number">0</span>
<span class="org-variable-name">alreadymounted</span>=$<span class="org-rainbow-delimiters-depth-2">(</span><span class="org-sh-quoted-exec">lsblk</span> -nrpo <span class="org-string">"name,type,mountpoint"</span> | awk <span class="org-string">'$3!~/\/boot|\/home$|SWAP/&amp;&amp;length($3)&gt;1{printf "-not ( -path *%s -prune ) ",$3}'</span><span class="org-rainbow-delimiters-depth-2">)</span>
getmount <span class="org-string">"/mnt /media /mount /home -maxdepth 5 -type d </span><span class="org-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">alreadymounted</span></span><span class="org-string">"</span>
<span class="org-variable-name">partitiontype</span>=<span class="org-string">"</span><span class="org-string"><span class="org-sh-quoted-exec">$(</span></span><span class="org-sh-quoted-exec">lsblk</span><span class="org-string"><span class="org-sh-quoted-exec"> -no "fstype" "</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">chosen</span></span></span><span class="org-string"><span class="org-sh-quoted-exec">")</span></span><span class="org-string">"</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">partitiontype</span></span><span class="org-string">"</span><span class="org-keyword"> in</span>
<span class="org-string">"vfat"</span>) <span class="org-type">sudo</span> -A mount -t vfat <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-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">mp</span></span><span class="org-string">"</span> -o rw,<span class="org-variable-name">umask</span>=<span class="org-highlight-numbers-number">0000</span>;;
*) <span class="org-type">sudo</span> -A mount <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-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">mp</span></span><span class="org-string">"</span>; <span class="org-variable-name">user</span>=<span class="org-string">"</span><span class="org-string"><span class="org-sh-quoted-exec">$(</span></span><span class="org-sh-quoted-exec">whoami</span><span class="org-string"><span class="org-sh-quoted-exec">)</span></span><span class="org-string">"</span>; <span class="org-variable-name">ug</span>=<span class="org-string">"</span><span class="org-string"><span class="org-sh-quoted-exec">$(</span></span><span class="org-sh-quoted-exec">groups</span><span class="org-string"><span class="org-sh-quoted-exec"> | awk '{print </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">"</span>; <span class="org-type">sudo</span> -A <span class="org-type">chown</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">user</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">ug</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">mp</span></span><span class="org-string">"</span>;;
<span class="org-keyword">esac</span>
notify-send <span class="org-string">"&#128187; USB mounting"</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"> mounted to </span><span class="org-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">mp</span></span><span class="org-string">."</span>
<span class="org-rainbow-delimiters-depth-1">}</span>
<span class="org-function-name">mountandroid</span><span class="org-rainbow-delimiters-depth-1">()</span> <span class="org-rainbow-delimiters-depth-1">{</span> <span class="org-sh-escaped-newline">\</span>
<span class="org-variable-name">chosen</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-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">anddrives</span></span></span><span class="org-string"><span class="org-sh-quoted-exec">" | dmenu -i -p "Which Android device?")</span></span><span class="org-string">"</span> || <span class="org-keyword">exit</span> <span class="org-highlight-numbers-number">1</span>
<span class="org-variable-name">chosen</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-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">chosen</span></span></span><span class="org-string"><span class="org-sh-quoted-exec">" | cut -d : -f 1)</span></span><span class="org-string">"</span>
getmount <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"> -maxdepth 3 -type d"</span>
simple-mtpfs --device <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-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">mp</span></span><span class="org-string">"</span>
<span class="org-type">echo</span> <span class="org-string">"OK"</span> | dmenu -i -p <span class="org-string">"Tap Allow on your phone if it asks for permission and then press enter"</span> || <span class="org-keyword">exit</span> <span class="org-highlight-numbers-number">1</span>
simple-mtpfs --device <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-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">mp</span></span><span class="org-string">"</span>
notify-send <span class="org-string">"&#129302; Android Mounting"</span> <span class="org-string">"Android device mounted to </span><span class="org-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">mp</span></span><span class="org-string">."</span>
<span class="org-rainbow-delimiters-depth-1">}</span>
<span class="org-function-name">asktype</span><span class="org-rainbow-delimiters-depth-1">()</span> <span class="org-rainbow-delimiters-depth-1">{</span> <span class="org-sh-escaped-newline">\</span>
<span class="org-variable-name">choice</span>=<span class="org-string">"</span><span class="org-string"><span class="org-sh-quoted-exec">$(</span></span><span class="org-sh-quoted-exec">printf</span><span class="org-string"><span class="org-sh-quoted-exec"> "USB\\nAndroid" | dmenu -i -p "Mount a USB drive or Android device?")</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">case</span> $<span class="org-variable-name">choice</span><span class="org-keyword"> in</span>
USB) mountusb ;;
Android) mountandroid ;;
<span class="org-keyword">esac</span>
<span class="org-rainbow-delimiters-depth-1">}</span>
<span class="org-variable-name">anddrives</span>=$<span class="org-rainbow-delimiters-depth-1">(</span><span class="org-sh-quoted-exec">simple-mtpfs</span> -l <span class="org-highlight-numbers-number">2</span>&gt;/dev/null<span class="org-rainbow-delimiters-depth-1">)</span>
<span class="org-variable-name">usbdrives</span>=<span class="org-string">"</span><span class="org-string"><span class="org-sh-quoted-exec">$(</span></span><span class="org-sh-quoted-exec">lsblk</span><span class="org-string"><span class="org-sh-quoted-exec"> -rpo "name,type,size,mountpoint" | awk '</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">4</span></span></span><span class="org-string"><span class="org-sh-quoted-exec">==""{printf "%s (%s)</span></span><span class="org-string">\n",</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 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">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">usbdrives</span></span><span class="org-string">"</span> <span class="org-rainbow-delimiters-depth-1">]</span>; <span class="org-keyword">then</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">anddrives</span></span><span class="org-string">"</span> <span class="org-rainbow-delimiters-depth-1">]</span> &amp;&amp; <span class="org-type">echo</span> <span class="org-string">"No USB drive or Android device detected"</span> &amp;&amp; <span class="org-keyword">exit</span>
<span class="org-type">echo</span> <span class="org-string">"Android device(s) detected."</span>
mountandroid
<span class="org-keyword">else</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">anddrives</span></span><span class="org-string">"</span> <span class="org-rainbow-delimiters-depth-1">]</span>; <span class="org-keyword">then</span>
<span class="org-type">echo</span> <span class="org-string">"USB drive(s) detected."</span>
mountusb
<span class="org-keyword">else</span>
<span class="org-type">echo</span> <span class="org-string">"Mountable USB drive(s) and Android device(s) detected."</span>
asktype
<span class="org-keyword">fi</span>
<span class="org-keyword">fi</span>
</pre>
</div>
</div>
</div>
2021-01-01 20:12:34 +01:00
<div id="outline-container-dmenuumount" class="outline-2">
<h2 id="dmenuumount"><code>dmenuumount</code> - Unmount USB and Android devices</h2>
<div class="outline-text-2" id="text-dmenuumount">
2020-11-03 16:27:09 +01:00
<p>
Script taken from Luke Smith.
</p>
<div class="org-src-container">
<pre class="src src-bash"><span class="org-function-name">unmountusb</span><span class="org-rainbow-delimiters-depth-1">()</span> <span class="org-rainbow-delimiters-depth-1">{</span>
<span class="org-rainbow-delimiters-depth-2">[</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">drives</span></span><span class="org-string">"</span> <span class="org-rainbow-delimiters-depth-2">]</span> &amp;&amp; <span class="org-keyword">exit</span>
<span class="org-variable-name">chosen</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-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">drives</span></span></span><span class="org-string"><span class="org-sh-quoted-exec">" | dmenu -i -p "Unmount which drive?")</span></span><span class="org-string">"</span> || <span class="org-keyword">exit</span> <span class="org-highlight-numbers-number">1</span>
<span class="org-variable-name">chosen</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-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">chosen</span></span></span><span class="org-string"><span class="org-sh-quoted-exec">" | awk '{print </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">"</span>
<span class="org-rainbow-delimiters-depth-2">[</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">chosen</span></span><span class="org-string">"</span> <span class="org-rainbow-delimiters-depth-2">]</span> &amp;&amp; <span class="org-keyword">exit</span>
<span class="org-type">sudo</span> -A umount <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> &amp;&amp; notify-send <span class="org-string">"&#128187; USB unmounting"</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"> unmounted."</span>
<span class="org-rainbow-delimiters-depth-1">}</span>
<span class="org-function-name">unmountandroid</span><span class="org-rainbow-delimiters-depth-1">()</span> <span class="org-rainbow-delimiters-depth-1">{</span> <span class="org-sh-escaped-newline">\</span>
<span class="org-variable-name">chosen</span>=<span class="org-string">"</span><span class="org-string"><span class="org-sh-quoted-exec">$(</span></span><span class="org-sh-quoted-exec">awk</span><span class="org-string"><span class="org-sh-quoted-exec"> '/simple-mtpfs/ {print </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">}' /etc/mtab | dmenu -i -p "Unmount which device?")</span></span><span class="org-string">"</span> || <span class="org-keyword">exit</span> <span class="org-highlight-numbers-number">1</span>
<span class="org-rainbow-delimiters-depth-2">[</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">chosen</span></span><span class="org-string">"</span> <span class="org-rainbow-delimiters-depth-2">]</span> &amp;&amp; <span class="org-keyword">exit</span>
<span class="org-type">sudo</span> -A umount -l <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> &amp;&amp; notify-send <span class="org-string">"&#129302; Android unmounting"</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"> unmounted."</span>
<span class="org-rainbow-delimiters-depth-1">}</span>
<span class="org-function-name">asktype</span><span class="org-rainbow-delimiters-depth-1">()</span> <span class="org-rainbow-delimiters-depth-1">{</span> <span class="org-sh-escaped-newline">\</span>
<span class="org-variable-name">choice</span>=<span class="org-string">"</span><span class="org-string"><span class="org-sh-quoted-exec">$(</span></span><span class="org-sh-quoted-exec">printf</span><span class="org-string"><span class="org-sh-quoted-exec"> "USB\\nAndroid" | dmenu -i -p "Unmount a USB drive or Android device?")</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">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">choice</span></span><span class="org-string">"</span><span class="org-keyword"> in</span>
USB) unmountusb ;;
Android) unmountandroid ;;
<span class="org-keyword">esac</span>
<span class="org-rainbow-delimiters-depth-1">}</span>
<span class="org-variable-name">drives</span>=$<span class="org-rainbow-delimiters-depth-1">(</span><span class="org-sh-quoted-exec">lsblk</span> -nrpo <span class="org-string">"name,type,size,mountpoint"</span> | awk <span class="org-string">'$4!~/\/boot|\/home$|SWAP/&amp;&amp;length($4)&gt;1{printf "%s (%s)\n",$4,$3}'</span><span class="org-rainbow-delimiters-depth-1">)</span>
<span class="org-keyword">if</span> <span class="org-negation-char">!</span> <span class="org-type">grep</span> simple-mtpfs /etc/mtab; <span class="org-keyword">then</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">drives</span></span><span class="org-string">"</span> <span class="org-rainbow-delimiters-depth-1">]</span> &amp;&amp; <span class="org-type">echo</span> <span class="org-string">"No drives to unmount."</span> &amp;&amp; <span class="org-keyword">exit</span>
<span class="org-type">echo</span> <span class="org-string">"Unmountable USB drive detected."</span>
unmountusb
<span class="org-keyword">else</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">drives</span></span><span class="org-string">"</span> <span class="org-rainbow-delimiters-depth-1">]</span>
<span class="org-keyword">then</span>
<span class="org-type">echo</span> <span class="org-string">"Unmountable Android device detected."</span>
unmountandroid
<span class="org-keyword">else</span>
<span class="org-type">echo</span> <span class="org-string">"Unmountable USB drive(s) and Android device(s) detected."</span>
asktype
<span class="org-keyword">fi</span>
<span class="org-keyword">fi</span>
2020-01-11 22:04:45 +01:00
</pre>
</div>
</div>
</div>
2021-01-08 01:43:48 +01:00
<div id="outline-container-dmenukill" class="outline-2">
<h2 id="dmenukill"><code>dmenukill</code> - Kill program using Dmenu</h2>
<div class="outline-text-2" id="text-dmenukill">
<div class="org-src-container">
<pre class="src src-bash"><span class="org-variable-name">ps_line</span>=$<span class="org-rainbow-delimiters-depth-1">(</span><span class="org-sh-quoted-exec">ps</span> -u $<span class="org-variable-name">USER</span> k -size -o <span class="org-variable-name">pid</span>=,%<span class="org-variable-name">mem</span>=,%<span class="org-variable-name">cpu</span>=,<span class="org-variable-name">comm</span>= | dmenu -i -l <span class="org-highlight-numbers-number">15</span><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-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">ps_line</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">pid</span>=$<span class="org-rainbow-delimiters-depth-1">(</span><span class="org-sh-quoted-exec">echo</span> $<span class="org-variable-name">ps_line</span> | awk <span class="org-string">'{print $1}'</span><span class="org-rainbow-delimiters-depth-1">)</span>
<span class="org-variable-name">name</span>=$<span class="org-rainbow-delimiters-depth-1">(</span><span class="org-sh-quoted-exec">echo</span> $<span class="org-variable-name">ps_line</span> | awk <span class="org-string">'{print $4}'</span><span class="org-rainbow-delimiters-depth-1">)</span>
<span class="org-type">kill</span> -15 $<span class="org-variable-name">pid</span> &amp;&amp; <span class="org-sh-escaped-newline">\</span>
2022-05-09 10:05:23 +02:00
notify-send <span class="org-string">"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">name</span></span><span class="org-string"> (PID </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> &amp;
2021-01-08 01:43:48 +01:00
<span class="org-keyword">fi</span>
</pre>
</div>
</div>
</div>
2021-01-01 20:12:34 +01:00
<div id="outline-container-nordvpn-toggle" class="outline-2">
<h2 id="nordvpn-toggle"><code>nordvpn-toggle</code> - Connect to VPN using NordVPN</h2>
<div class="outline-text-2" id="text-nordvpn-toggle">
<p>
To use this this, <code>nordvpn</code> must be installed: <code>yay -S nordvpn-bin</code>.
</p>
2020-01-11 22:04:45 +01:00
<div class="org-src-container">
2021-01-01 20:12:34 +01:00
<pre class="src src-bash"><span class="org-variable-name">tmpfile</span>=<span class="org-string">"/tmp/vpnstatus"</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-rainbow-delimiters-depth-3">(</span><span class="org-sh-quoted-exec">nordvpn</span> status<span class="org-rainbow-delimiters-depth-3">)</span> == *<span class="org-string">"Connected"</span>* <span class="org-rainbow-delimiters-depth-2">]</span><span class="org-rainbow-delimiters-depth-1">]</span>; <span class="org-keyword">then</span>
nordvpn disconnect &amp;&amp; <span class="org-sh-escaped-newline">\</span>
2022-05-09 10:05:23 +02:00
notify-send <span class="org-string">"VPN"</span> <span class="org-string">"Disconnected"</span> &amp;&amp; <span class="org-sh-escaped-newline">\</span>
2021-01-01 20:12:34 +01:00
<span class="org-type">echo</span> <span class="org-string">"off"</span> &gt; $<span class="org-variable-name">tmpfile</span>;
2020-11-03 16:27:09 +01:00
<span class="org-keyword">else</span>
2021-01-01 20:12:34 +01:00
<span class="org-comment-delimiter"># </span><span class="org-comment">Select Country to connect to</span>
<span class="org-variable-name">country</span>=<span class="org-sh-quoted-exec">`</span><span class="org-type"><span class="org-sh-quoted-exec">cat</span></span><span class="org-sh-quoted-exec"> ~/.local/data/nordvpn_countries.txt | rofi -i -dmenu | sed 's/\s/_/g'`</span>;
2022-05-09 10:05:23 +02:00
notify-send <span class="org-string">"VPN"</span> <span class="org-string">"Connecting to </span><span class="org-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">country</span></span><span class="org-string">..."</span>;
2021-01-01 20:12:34 +01:00
nordvpn connect $<span class="org-variable-name">country</span> &amp;&amp; <span class="org-sh-escaped-newline">\</span>
2022-05-09 10:05:23 +02:00
notify-send <span class="org-string">"VPN"</span> <span class="org-string">"Connected to </span><span class="org-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">country</span></span><span class="org-string">"</span> &amp;&amp; <span class="org-sh-escaped-newline">\</span>
2021-01-01 20:12:34 +01:00
<span class="org-type">echo</span> <span class="org-string">"on"</span> &gt; $<span class="org-variable-name">tmpfile</span>;
2020-11-03 16:27:09 +01:00
<span class="org-keyword">fi</span>
2020-01-11 22:04:45 +01:00
</pre>
</div>
</div>
</div>
2021-01-01 20:12:34 +01:00
<div id="outline-container-i3exit" class="outline-2">
<h2 id="i3exit"><code>i3exit</code> - Manage lock, suspend, reboot, &#x2026;</h2>
<div class="outline-text-2" id="text-i3exit">
2020-01-11 22:04:45 +01:00
<div class="org-src-container">
2020-11-03 16:27:09 +01:00
<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>
2020-05-26 08:40:15 +02:00
2020-11-03 16:27:09 +01:00
<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>)
2020-05-26 08:40:15 +02:00
~/.local/bin/lockscreen
2020-01-11 22:04:45 +01:00
;;
2020-11-03 16:27:09 +01:00
<span class="org-string">"Exit"</span>)
2021-01-01 20:12:34 +01:00
<span class="org-type">pkill</span> -15 -t tty<span class="org-string">"</span><span class="org-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">XDG_VTNR</span></span><span class="org-string">"</span> Xorg
2020-01-11 22:04:45 +01:00
;;
2020-11-03 16:27:09 +01:00
<span class="org-string">"Logout"</span>)
loginctl terminate-session <span class="org-sh-quoted-exec">`loginctl session-status | head -n 1 | awk '{print $1}'`</span>
2020-05-26 08:40:15 +02:00
;;
2020-11-03 16:27:09 +01:00
<span class="org-string">"Suspend"</span>)
2020-05-26 08:40:15 +02:00
systemctl suspend &amp;&amp; ~/.local/bin/lockscreen
2020-01-11 22:04:45 +01:00
;;
2020-11-03 16:27:09 +01:00
<span class="org-string">"Hibernate"</span>)
2020-05-26 08:40:15 +02:00
systemctl hibernate &amp;&amp; ~/.local/bin/lockscreen
2020-01-11 22:04:45 +01:00
;;
2020-11-03 16:27:09 +01:00
<span class="org-string">"Reboot"</span>)
<span class="org-variable-name">confirmation</span>=$<span class="org-rainbow-delimiters-depth-1">(</span><span class="org-sh-quoted-exec">echo</span> -e <span class="org-string">"Yes\nNo"</span> | rofi -i -p <span class="org-string">"Are you sure you want to Reboot?"</span> -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">confirmation</span></span><span class="org-string">"</span><span class="org-keyword"> in</span>
<span class="org-string">"Yes"</span>)
systemctl reboot
;;
<span class="org-keyword">esac</span>
2020-01-11 22:04:45 +01:00
;;
2020-11-03 16:27:09 +01:00
<span class="org-string">"Shutdown"</span>)
<span class="org-variable-name">confirmation</span>=$<span class="org-rainbow-delimiters-depth-1">(</span><span class="org-sh-quoted-exec">echo</span> -e <span class="org-string">"Yes\nNo"</span> | rofi -i -p <span class="org-string">"Are you sure you want to Shutdown?"</span> -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">confirmation</span></span><span class="org-string">"</span><span class="org-keyword"> in</span>
<span class="org-string">"Yes"</span>)
systemctl poweroff
;;
<span class="org-keyword">esac</span>
2020-01-11 22:04:45 +01:00
;;
*)
2020-11-03 16:27:09 +01:00
<span class="org-type">echo</span> <span class="org-string">"== ! i3exit: missing or invalid argument ! =="</span>
<span class="org-keyword">exit</span> <span class="org-highlight-numbers-number">2</span>
<span class="org-keyword">esac</span>
2020-01-11 22:04:45 +01:00
2020-11-03 16:27:09 +01:00
<span class="org-keyword">exit</span> <span class="org-highlight-numbers-number">0</span>
2020-01-11 22:04:45 +01:00
</pre>
</div>
</div>
</div>
2021-01-01 20:12:34 +01:00
<div id="outline-container-askpass-rofi" class="outline-2">
<h2 id="askpass-rofi"><code>askpass-rofi</code> - GUI prompt for passwords</h2>
<div class="outline-text-2" id="text-askpass-rofi">
2020-05-26 08:40:15 +02:00
<p>
Take password prompt from STDIN, print password to STDOUT.
The sed piece just removes the colon from the provided prompt: <code>rofi -p</code> already gives us a colon
</p>
2021-01-01 20:12:34 +01:00
2020-01-11 22:04:45 +01:00
<div class="org-src-container">
2020-11-03 16:27:09 +01:00
<pre class="src src-bash">rofi -dmenu <span class="org-sh-escaped-newline">\</span>
-password <span class="org-sh-escaped-newline">\</span>
-no-fixed-num-lines <span class="org-sh-escaped-newline">\</span>
-p <span class="org-string">"</span><span class="org-string"><span class="org-sh-quoted-exec">$(</span></span><span class="org-sh-quoted-exec">printf</span><span class="org-string"><span class="org-sh-quoted-exec"> "</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">" | sed s/://)</span></span><span class="org-string">"</span>
2020-01-11 22:04:45 +01:00
</pre>
</div>
</div>
</div>
2022-05-09 10:05:23 +02:00
<div id="outline-container-get-pass" class="outline-2">
<h2 id="get-pass"><code>get-pass</code> - Get Stored Password</h2>
<div class="outline-text-2" id="text-get-pass">
<div class="org-src-container">
<pre class="src src-bash">pass $<span class="org-highlight-numbers-number">1</span> | sed -n 1p
</pre>
</div>
</div>
</div>
2021-01-01 20:12:34 +01:00
<div id="outline-container-screenshot" class="outline-2">
<h2 id="screenshot"><code>screenshot</code> - Take Screenshot</h2>
<div class="outline-text-2" id="text-screenshot">
2020-01-11 22:04:45 +01:00
<div class="org-src-container">
2021-01-01 20:12:34 +01:00
<pre class="src src-bash"><span class="org-comment-delimiter"># </span><span class="org-comment">Ask for screenshot type</span>
<span class="org-variable-name">status</span>=$<span class="org-rainbow-delimiters-depth-1">(</span><span class="org-sh-quoted-exec">echo</span> -e <span class="org-string">"All\nGUI\nSelection\nCropped\nCopy\nPretty\nShadow\nWindow"</span> | rofi -i -dmenu -p <span class="org-string">"Type"</span><span class="org-rainbow-delimiters-depth-1">)</span>
2020-11-03 16:27:09 +01:00
<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">status</span></span><span class="org-string">"</span> <span class="org-rainbow-delimiters-depth-1">]</span>; <span class="org-keyword">then</span>
2021-01-01 20:12:34 +01:00
<span class="org-keyword">exit</span>;
2020-11-03 16:27:09 +01:00
<span class="org-keyword">fi</span>
2021-01-01 20:12:34 +01:00
<span class="org-comment-delimiter"># </span><span class="org-comment">Ask for filename if not copying the image</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">status</span> != <span class="org-string">"Copy"</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-variable-name">name</span>=<span class="org-sh-quoted-exec">$</span><span class="org-sh-quoted-exec"><span class="org-rainbow-delimiters-depth-1">(</span></span><span class="org-sh-quoted-exec">echo -e </span><span class="org-string"><span class="org-sh-quoted-exec">"screenshot-$(</span></span><span class="org-sh-quoted-exec">date</span><span class="org-string"><span class="org-sh-quoted-exec"> +"%m-%d-%y_%H-%M-%S")</span></span><span class="org-string">"</span> | rofi -i -dmenu -p <span class="org-string">"Filename"</span><span class="org-rainbow-delimiters-depth-1">)</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">name</span></span><span class="org-string">"</span> <span class="org-rainbow-delimiters-depth-1">]</span>; <span class="org-keyword">then</span>
<span class="org-keyword">exit</span>;
<span class="org-keyword">fi</span>
<span class="org-variable-name">filename</span>=~/Pictures/$<span class="org-variable-name">name</span>.png
2020-11-03 16:27:09 +01:00
<span class="org-keyword">fi</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">status</span></span><span class="org-string">"</span><span class="org-keyword"> in</span>
<span class="org-string">"All"</span>)
2021-01-01 20:12:34 +01:00
maim -u $<span class="org-variable-name">filename</span> ;;
2020-11-03 16:27:09 +01:00
<span class="org-string">"GUI"</span>)
2021-01-01 20:12:34 +01:00
flameshot gui -r &gt; $<span class="org-variable-name">filename</span> &amp;&amp; <span class="org-sh-escaped-newline">\</span>
<span class="org-type">pkill</span> flameshot;;
2020-11-03 16:27:09 +01:00
<span class="org-string">"Selection"</span>)
2021-01-01 20:12:34 +01:00
maim -u -s $<span class="org-variable-name">filename</span> ;;
2020-11-03 16:27:09 +01:00
<span class="org-string">"Cropped"</span>)
2021-01-01 20:12:34 +01:00
maim -u -s $<span class="org-variable-name">filename</span> &amp;&amp; convert -trim $<span class="org-variable-name">filename</span> $<span class="org-variable-name">filename</span> ;;
2020-11-03 16:27:09 +01:00
<span class="org-string">"Copy"</span>)
2021-01-01 20:12:34 +01:00
maim -u -s | xclip -selection clipboard -t image/png ;;
2020-11-03 16:27:09 +01:00
<span class="org-string">"Shadow"</span>)
2021-01-01 20:12:34 +01:00
maim -u -s | convert - <span class="org-string">\(</span> +clone -background black -shadow 80x3+5+5 <span class="org-string">\)</span> +swap -background none -layers merge +repage $<span class="org-variable-name">filename</span> ;;
<span class="org-string">"Pretty"</span>)
maim -u -s $<span class="org-variable-name">filename</span> &amp;&amp; <span class="org-sh-escaped-newline">\</span>
convert $<span class="org-variable-name">filename</span> <span class="org-string">\(</span> +clone -alpha extract -draw <span class="org-string">'fill black polygon 0,0 0,5 5,0 fill white circle 5,5 5,0'</span> <span class="org-string">\(</span> +clone -flip <span class="org-string">\)</span> -compose Multiply -composite <span class="org-string">\(</span> +clone -flop <span class="org-string">\)</span> -compose Multiply -composite <span class="org-string">\)</span> -alpha off -compose CopyOpacity -composite $<span class="org-variable-name">filename</span> &amp;&amp; <span class="org-sh-escaped-newline">\</span>
convert $<span class="org-variable-name">filename</span> <span class="org-string">\(</span> +clone -background black -shadow 40x5+0+0 <span class="org-string">\)</span> +swap -background none -layers merge +repage $<span class="org-variable-name">filename</span> ;;
<span class="org-string">"Window"</span>)
maim -u -i $<span class="org-rainbow-delimiters-depth-1">(</span><span class="org-sh-quoted-exec">xdotool</span> selectwindow<span class="org-rainbow-delimiters-depth-1">)</span> $<span class="org-variable-name">filename</span> ;;
2020-11-03 16:27:09 +01:00
<span class="org-keyword">esac</span>
2020-01-11 22:04:45 +01:00
</pre>
</div>
</div>
</div>
2021-01-01 20:12:34 +01:00
<div id="outline-container-network-toggle" class="outline-2">
<h2 id="network-toggle"><code>network-toggle</code> - Toggle Network</h2>
<div class="outline-text-2" id="text-network-toggle">
<p>
Minimal network manager to just toggle the Wifi or Ethernet connection.
</p>
2020-05-26 08:40:15 +02:00
<div class="org-src-container">
2020-11-03 16:27:09 +01:00
<pre class="src src-bash"><span class="org-variable-name">result</span>=$<span class="org-rainbow-delimiters-depth-1">(</span><span class="org-sh-quoted-exec">nmcli</span> device | sed <span class="org-string">'1d'</span> | dmenu -l <span class="org-highlight-numbers-number">20</span><span class="org-rainbow-delimiters-depth-1">)</span>;
2020-04-05 11:30:26 +02:00
2020-11-03 16:27:09 +01:00
<span class="org-variable-name">interface</span>=$<span class="org-rainbow-delimiters-depth-1">(</span><span class="org-sh-quoted-exec">echo</span> $<span class="org-variable-name">result</span> | awk -F <span class="org-string">' '</span> <span class="org-string">'{print $1}'</span><span class="org-rainbow-delimiters-depth-1">)</span>;
<span class="org-variable-name">status</span>=$<span class="org-rainbow-delimiters-depth-1">(</span><span class="org-sh-quoted-exec">echo</span> $<span class="org-variable-name">result</span> | awk -F <span class="org-string">' '</span> <span class="org-string">'{print $3}'</span><span class="org-rainbow-delimiters-depth-1">)</span>;
2020-05-26 08:40:15 +02:00
2020-11-03 16:27:09 +01:00
<span class="org-keyword">if</span> <span class="org-rainbow-delimiters-depth-1">[</span> $<span class="org-variable-name">status</span> == <span class="org-string">'disconnected'</span> <span class="org-rainbow-delimiters-depth-1">]</span>; <span class="org-keyword">then</span>
nmcli device connect $<span class="org-variable-name">interface</span>
<span class="org-keyword">else</span>
nmcli device disconnect $<span class="org-variable-name">interface</span>
<span class="org-keyword">fi</span>
2020-05-26 08:40:15 +02:00
</pre>
</div>
</div>
</div>
2021-01-01 20:12:34 +01:00
<div id="outline-container-make-gif" class="outline-2">
<h2 id="make-gif"><code>make-gif</code> - Convert an <code>MP4</code> video to <code>GIF</code></h2>
<div class="outline-text-2" id="text-make-gif">
<p>
First argument is the <code>mp4</code> file and the second argument is the output <code>gif</code> file.
</p>
2020-01-11 22:04:45 +01:00
<div class="org-src-container">
2020-11-03 16:27:09 +01:00
<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>
2020-05-26 08:40:15 +02:00
2020-11-03 16:27:09 +01:00
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>
2020-01-11 22:04:45 +01:00
</pre>
</div>
</div>
</div>
2021-01-01 20:12:34 +01:00
<div id="outline-container-yt-audio" class="outline-2">
<h2 id="yt-audio"><code>yt-audio</code> - Download-Audio from youtube</h2>
<div class="outline-text-2" id="text-yt-audio">
2020-01-11 22:04:45 +01:00
<div class="org-src-container">
2020-11-03 16:27:09 +01:00
<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>
2021-01-08 01:43:48 +01:00
tmux split -v -l <span class="org-highlight-numbers-number">5</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
2020-11-03 16:27:09 +01:00
<span class="org-keyword">else</span>
2021-01-08 01:43:48 +01:00
<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;
2020-11-03 16:27:09 +01:00
<span class="org-keyword">fi</span>
2020-01-11 22:04:45 +01:00
</pre>
</div>
</div>
</div>
2021-01-01 20:12:34 +01:00
<div id="outline-container-yt-video" class="outline-2">
<h2 id="yt-video"><code>yt-video</code> - Download-Video from youtube</h2>
<div class="outline-text-2" id="text-yt-video">
2020-01-11 22:04:45 +01:00
<div class="org-src-container">
2020-11-03 16:27:09 +01:00
<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>
2021-01-08 01:43:48 +01:00
tmux split -v -l <span class="org-highlight-numbers-number">5</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
2020-11-03 16:27:09 +01:00
<span class="org-keyword">else</span>
2021-01-08 01:43:48 +01:00
<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;
2020-11-03 16:27:09 +01:00
<span class="org-keyword">fi</span>
2020-01-11 22:04:45 +01:00
</pre>
</div>
</div>
</div>
2021-01-01 20:12:34 +01:00
<div id="outline-container-setbg" class="outline-2">
<h2 id="setbg"><code>setbg</code> - Set Background</h2>
<div class="outline-text-2" id="text-setbg">
<p>
First argument is either:
</p>
<ul class="org-ul">
<li>the background file</li>
<li>a directory, in such case it will pick a random picture file from that directory</li>
</ul>
2020-05-26 08:40:15 +02:00
<div class="org-src-container">
2020-11-03 16:27:09 +01:00
<pre class="src src-bash"><span class="org-variable-name">bgloc</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">{XDG_CACHE_HOME:-$HOME/.cache/}</span></span><span class="org-string">/bg"</span>
2020-01-11 22:04:45 +01:00
2021-01-01 20:12:34 +01:00
<span class="org-comment-delimiter"># </span><span class="org-comment">If the argument is a file</span>
2020-11-03 16:27:09 +01:00
<span class="org-rainbow-delimiters-depth-1">[</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> <span class="org-rainbow-delimiters-depth-1">]</span> &amp;&amp; <span class="org-type">ln</span> -sf <span class="org-string">"</span><span class="org-string"><span class="org-sh-quoted-exec">$(</span></span><span class="org-sh-quoted-exec">readlink</span><span class="org-string"><span class="org-sh-quoted-exec"> -f "</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">"</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">bgloc</span></span><span class="org-string">"</span>
2020-05-26 08:40:15 +02:00
2021-01-01 20:12:34 +01:00
<span class="org-comment-delimiter"># </span><span class="org-comment">If the argument is a directory</span>
2020-11-03 16:27:09 +01:00
<span class="org-rainbow-delimiters-depth-1">[</span> -d <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> &amp;&amp; <span class="org-type">ln</span> -sf <span class="org-string">"</span><span class="org-string"><span class="org-sh-quoted-exec">$(</span></span><span class="org-sh-quoted-exec">find</span><span class="org-string"><span class="org-sh-quoted-exec"> "$(</span></span><span class="org-sh-quoted-exec">readlink</span><span class="org-string"><span class="org-sh-quoted-exec"> -f "</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">" -iregex '.*.\(jpg\|jpeg\|png\|gif\)' -type f | shuf -n 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">bgloc</span></span><span class="org-string">"</span>
2020-05-26 08:40:15 +02:00
2021-01-01 20:12:34 +01:00
<span class="org-comment-delimiter"># </span><span class="org-comment">Set the wallpaper</span>
2020-11-03 16:27:09 +01:00
xwallpaper --zoom <span class="org-string">"</span><span class="org-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">bgloc</span></span><span class="org-string">"</span>
2020-05-26 08:40:15 +02:00
</pre>
</div>
</div>
</div>
2020-11-03 16:27:09 +01:00
2021-01-01 20:12:34 +01:00
<div id="outline-container-insert-unicode" class="outline-2">
<h2 id="insert-unicode"><code>insert-unicode</code> - Insert Unicode Icon</h2>
<div class="outline-text-2" id="text-insert-unicode">
<p>
The list of emojis is available <a href="data.html#emojis">here</a>.
</p>
2020-01-11 22:04:45 +01:00
<div class="org-src-container">
2020-11-03 16:27:09 +01:00
<pre class="src src-bash"><span class="org-comment-delimiter"># </span><span class="org-comment">Must have xclip installed to even show menu.</span>
xclip -h <span class="org-highlight-numbers-number">2</span>&gt;/dev/null || <span class="org-keyword">exit</span> <span class="org-highlight-numbers-number">1</span>
2020-01-11 22:04:45 +01:00
2020-11-03 16:27:09 +01:00
<span class="org-variable-name">chosen</span>=$<span class="org-rainbow-delimiters-depth-1">(</span><span class="org-sh-quoted-exec">cut</span> -d <span class="org-string">';'</span> -f1 ~/.local/data/emojis | rofi -dmenu -i -l <span class="org-highlight-numbers-number">20</span> | sed <span class="org-string">"s/ .*//"</span><span class="org-rainbow-delimiters-depth-1">)</span>
2020-01-11 22:04:45 +01:00
2020-11-03 16:27:09 +01:00
<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>
2020-05-26 08:40:15 +02:00
2020-11-03 16:27:09 +01:00
<span class="org-comment-delimiter"># </span><span class="org-comment">If you run this command with an argument, it will automatically insert the character.</span>
<span class="org-keyword">if</span> <span class="org-rainbow-delimiters-depth-1">[</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">1</span></span><span class="org-string">"</span> <span class="org-rainbow-delimiters-depth-1">]</span>; <span class="org-keyword">then</span>
2020-05-26 08:40:15 +02:00
xdotool key Shift+Insert
2020-11-03 16:27:09 +01:00
<span class="org-keyword">else</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">chosen</span></span><span class="org-string">"</span> | tr -d <span class="org-string">'\n'</span> | xsel -ib
2022-05-09 10:05:23 +02:00
notify-send <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">' copied to clipboard."</span> &amp;
2020-11-03 16:27:09 +01:00
<span class="org-keyword">fi</span>
2020-01-11 22:04:45 +01:00
</pre>
</div>
</div>
</div>
2021-01-01 20:12:34 +01:00
<div id="outline-container-insert-nerd-fonts" class="outline-2">
<h2 id="insert-nerd-fonts"><code>insert-nerd-fonts</code> - Insert Nerd Font Icon</h2>
<div class="outline-text-2" id="text-insert-nerd-fonts">
<p>
The list of emojis is available <a href="data.html#nerd-fonts">here</a>.
</p>
2020-01-11 22:04:45 +01:00
<div class="org-src-container">
2020-11-03 16:27:09 +01:00
<pre class="src src-bash"><span class="org-comment-delimiter"># </span><span class="org-comment">Must have xsel installed to even show menu.</span>
xsel -h <span class="org-highlight-numbers-number">2</span>&gt;/dev/null || <span class="org-keyword">exit</span> <span class="org-highlight-numbers-number">1</span>
2020-05-26 08:40:15 +02:00
2020-11-03 16:27:09 +01:00
<span class="org-variable-name">chosen</span>=$<span class="org-rainbow-delimiters-depth-1">(</span><span class="org-sh-quoted-exec">cat</span> ~/.local/data/nerd-fonts | rofi -dmenu -i -l <span class="org-highlight-numbers-number">20</span> | sed <span class="org-string">"s/ .*//"</span><span class="org-rainbow-delimiters-depth-1">)</span>
2020-05-26 08:40:15 +02:00
2020-11-03 16:27:09 +01:00
<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>
2020-05-26 08:40:15 +02:00
2020-11-03 16:27:09 +01:00
<span class="org-comment-delimiter"># </span><span class="org-comment">If you run this command with an argument, it will automatically insert the character.</span>
<span class="org-keyword">if</span> <span class="org-rainbow-delimiters-depth-1">[</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">1</span></span><span class="org-string">"</span> <span class="org-rainbow-delimiters-depth-1">]</span>; <span class="org-keyword">then</span>
2020-05-26 08:40:15 +02:00
xdotool key Shift+Insert
2020-11-03 16:27:09 +01:00
<span class="org-keyword">else</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">chosen</span></span><span class="org-string">"</span> | tr -d <span class="org-string">'\n'</span> | xsel -ib
2022-05-09 10:05:23 +02:00
notify-send <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">' copied to clipboard."</span> &amp;
2020-11-03 16:27:09 +01:00
<span class="org-keyword">fi</span>
2020-01-11 22:04:45 +01:00
</pre>
</div>
</div>
</div>
2021-01-01 20:12:34 +01:00
<div id="outline-container-linkhandler" class="outline-2">
2021-10-25 14:37:10 +02:00
<h2 id="linkhandler"><code>linkhandler</code> - Open any URL with Default application</h2>
2021-01-01 20:12:34 +01:00
<div class="outline-text-2" id="text-linkhandler">
2020-05-26 08:40:15 +02:00
<p>
2021-01-01 20:12:34 +01:00
Inspired from <code>linkhandler</code> script (<a href="https://github.com/LukeSmithxyz/voidrice/">github</a>).
2021-10-25 14:37:10 +02:00
This is used to open any <b>url</b> with the wanted program.
2020-05-26 08:40:15 +02:00
</p>
2020-04-05 11:30:26 +02:00
2020-01-11 22:04:45 +01:00
<div class="org-src-container">
2020-11-03 16:27:09 +01:00
<pre class="src src-bash"><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">1</span></span><span class="org-string">"</span> <span class="org-rainbow-delimiters-depth-1">]</span> &amp;&amp; <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">BROWSER</span></span><span class="org-string">"</span>; <span class="org-keyword">exit</span>; <span class="org-rainbow-delimiters-depth-1">}</span>
2020-05-26 08:40:15 +02:00
2020-11-03 16:27:09 +01:00
<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>
2021-10-25 14:37:10 +02:00
*mkv|*webm|*mp4|*youtube.com/watch*|*youtube.com/playlist*|*youtu.be*|*gif)
setsid mpv -quiet <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> &gt;/dev/null <span class="org-highlight-numbers-number">2</span>&gt;&amp;<span class="org-highlight-numbers-number">1</span> &amp; ;;
*png|*jpg|*jpe|*jpeg)
<span class="org-type">curl</span> -sL <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> &gt; <span class="org-string">"/tmp/</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-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">" | sed "s/.*\///;s/%20/ /g")</span></span><span class="org-string">"</span> &amp;&amp; sxiv -a <span class="org-string">"/tmp/</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-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">" | sed "s/.*\///;s/%20/ /g")</span></span><span class="org-string">"</span> &gt;/dev/null <span class="org-highlight-numbers-number">2</span>&gt;&amp;<span class="org-highlight-numbers-number">1</span> &amp; ;;
*pdf|*cbz|*cbr)
<span class="org-type">curl</span> -sL <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> &gt; <span class="org-string">"/tmp/</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-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">" | sed "s/.*\///;s/%20/ /g")</span></span><span class="org-string">"</span> &amp;&amp; zathura <span class="org-string">"/tmp/</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-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">" | sed "s/.*\///;s/%20/ /g")</span></span><span class="org-string">"</span> &gt;/dev/null <span class="org-highlight-numbers-number">2</span>&gt;&amp;<span class="org-highlight-numbers-number">1</span> &amp; ;;
*svg)
<span class="org-type">curl</span> -sL <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> &gt; <span class="org-string">"/tmp/</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-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">" | sed "s/.*\///;s/%20/ /g")</span></span><span class="org-string">"</span> &amp;&amp; inkview <span class="org-string">"/tmp/</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-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">" | sed "s/.*\///;s/%20/ /g")</span></span><span class="org-string">"</span> &gt;/dev/null <span class="org-highlight-numbers-number">2</span>&gt;&amp;<span class="org-highlight-numbers-number">1</span> &amp; ;;
2020-05-26 08:40:15 +02:00
*mp3|*flac|*opus|*mp3?source*)
2021-01-01 20:12:34 +01:00
setsid <span class="org-type">curl</span> -LO <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> &gt;/dev/null <span class="org-highlight-numbers-number">2</span>&gt;&amp;<span class="org-highlight-numbers-number">1</span> &amp; ;;
2020-05-26 08:40:15 +02:00
*)
2021-10-25 14:37:10 +02:00
<span class="org-rainbow-delimiters-depth-1">[</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> <span class="org-rainbow-delimiters-depth-1">]</span> &amp;&amp; setsid -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">TERMINAL</span></span><span class="org-string">"</span> -e <span class="org-string">"</span><span class="org-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">EDITOR</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">1</span></span><span class="org-string">"</span> &gt;/dev/null <span class="org-highlight-numbers-number">2</span>&gt;&amp;<span class="org-highlight-numbers-number">1</span> || setsid -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">BROWSER</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">1</span></span><span class="org-string">"</span> &gt;/dev/null <span class="org-highlight-numbers-number">2</span>&gt;&amp;<span class="org-highlight-numbers-number">1</span>
2020-11-03 16:27:09 +01:00
<span class="org-keyword">esac</span>
2020-01-11 22:04:45 +01:00
</pre>
</div>
</div>
</div>
2020-03-01 22:51:16 +01:00
2021-10-25 14:37:10 +02:00
<div id="outline-container-filehandler" class="outline-2">
<h2 id="filehandler"><code>open</code> - Open any file using <code>rifle</code></h2>
<div class="outline-text-2" id="text-filehandler">
<p>
Simple alternative to <code>xdg-open</code>, uses the <code>rifle</code> program included with <code>ranger</code>.
The default applications are listed <a href="ranger.html#rifle">here</a>.
</p>
<div class="org-src-container">
<pre class="src src-bash">rifle -p $<span class="org-rainbow-delimiters-depth-1">(</span><span class="org-sh-quoted-exec">rifle</span> -l <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> | rofi -dmenu -i | sed -n -e <span class="org-string">'s/\([0-9]*\):.*/\1/p'</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">1</span></span><span class="org-string">"</span>
</pre>
</div>
</div>
</div>
2021-01-01 20:12:34 +01:00
<div id="outline-container-lockscreen" class="outline-2">
<h2 id="lockscreen"><code>lockscreen</code> - Lock Screen</h2>
<div class="outline-text-2" id="text-lockscreen">
2020-03-01 22:51:16 +01:00
<p>
2021-01-01 20:12:34 +01:00
A nice lockscreen that uses <code>i3lock</code>.
It takes a screenshot, pixelize it and overlay an image in the lockscreens folder.
2020-03-01 22:51:16 +01:00
</p>
2021-01-01 20:12:34 +01:00
2020-05-26 08:40:15 +02:00
<div class="org-src-container">
2021-01-01 20:12:34 +01:00
<pre class="src src-bash"><span class="org-comment-delimiter"># </span><span class="org-comment">First, turn off dunst</span>
killall -SIGUSR1 dunst &amp;&amp; <span class="org-type">echo</span> <span class="org-string">"off"</span> &gt; /tmp/dunststatus;
<span class="org-comment-delimiter"># </span><span class="org-comment">Turn off the music if it is playing.</span>
<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>
2020-11-03 16:27:09 +01:00
<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>
2021-01-01 20:12:34 +01:00
mpc pause
2020-11-03 16:27:09 +01:00
<span class="org-keyword">fi</span>
2020-03-01 22:51:16 +01:00
2021-01-01 20:12:34 +01:00
<span class="org-comment-delimiter"># </span><span class="org-comment">Take the screenshot and process it nicely</span>
<span class="org-variable-name">temp_file</span>=<span class="org-string">"/tmp/screen.png"</span>
2020-11-03 16:27:09 +01:00
<span class="org-type">rm</span> -f $<span class="org-variable-name">temp_file</span>
2021-01-01 20:12:34 +01:00
maim $<span class="org-variable-name">temp_file</span> &amp;&amp; <span class="org-sh-escaped-newline">\</span>
<span class="org-comment-delimiter"># </span><span class="org-comment">Pixelize the Screenshot</span>
convert $<span class="org-variable-name">temp_file</span> -scale 10% -scale 1000% $<span class="org-variable-name">temp_file</span> &amp;&amp; <span class="org-sh-escaped-newline">\</span>
<span class="org-comment-delimiter"># </span><span class="org-comment">Overlay a random image in the lockscreens folder</span>
composite -gravity center $<span class="org-rainbow-delimiters-depth-1">(</span><span class="org-sh-quoted-exec">find</span> ~/.local/data/lockscreens/ -type f | shuf -n <span class="org-highlight-numbers-number">1</span><span class="org-rainbow-delimiters-depth-1">)</span> $<span class="org-variable-name">temp_file</span> $<span class="org-variable-name">temp_file</span>;
<span class="org-comment-delimiter"># </span><span class="org-comment">Finally, lock the screen using =i3lock=</span>
i3lock --ignore-empty-password --nofork --image=$<span class="org-variable-name">temp_file</span> &amp;&amp; <span class="org-sh-escaped-newline">\</span>
<span class="org-comment-delimiter"># </span><span class="org-comment">When unlocking, restart dunst</span>
killall -SIGUSR2 dunst &amp;&amp; <span class="org-type">echo</span> <span class="org-string">"on"</span> &gt; /tmp/dunststatus
2020-03-01 22:51:16 +01:00
</pre>
</div>
2021-01-01 20:12:34 +01:00
</div>
</div>
2020-05-26 08:40:15 +02:00
2021-01-01 20:12:34 +01:00
<div id="outline-container-mopidy-restart" class="outline-2">
<h2 id="mopidy-restart"><code>mopidy-restart</code> - Restart Mopidy</h2>
<div class="outline-text-2" id="text-mopidy-restart">
2020-05-26 08:40:15 +02:00
<p>
2021-01-01 20:12:34 +01:00
Sometimes <code>mopidy</code> need to be restarted&#x2026;
2020-05-26 08:40:15 +02:00
</p>
2020-11-03 16:27:09 +01:00
2020-03-01 22:51:16 +01:00
<div class="org-src-container">
2020-11-03 16:27:09 +01:00
<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>
<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>
<span class="org-type">echo</span> <span class="org-string">"Killed mopidy."</span>
2021-01-01 20:12:34 +01:00
2020-11-03 16:27:09 +01:00
<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-03-01 22:51:16 +01:00
</pre>
</div>
</div>
</div>
2021-01-01 20:12:34 +01:00
<div id="outline-container-upload" class="outline-2">
<h2 id="upload"><code>upload</code> - Upload Script</h2>
<div class="outline-text-2" id="text-upload">
<p>
Upload a file to <a href="https://0x0.st/">https://0x0.st/</a> and copy the generated url.
</p>
2020-03-01 22:51:16 +01:00
<div class="org-src-container">
2020-11-03 16:27:09 +01:00
<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">curl</span></span><span class="org-string"> --progress-bar -F\"file=@</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">\" https://0x0.st | xsel -ib;"</span> &amp;&amp; tmux select-pane -U
<span class="org-keyword">else</span>
<span class="org-type">curl</span> --progress-bar -F<span class="org-string">"file=@</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> https://0x0.st | xsel -ib &amp;&amp; <span class="org-sh-escaped-newline">\</span>
2022-05-09 10:05:23 +02:00
notify-send <span class="org-string">'Upload'</span> <span class="org-string">'Successful'</span> || <span class="org-sh-escaped-newline">\</span>
notify-send --urgency=critical <span class="org-string">'Upload'</span> <span class="org-string">'Failed'</span>
2020-11-03 16:27:09 +01:00
<span class="org-keyword">fi</span>
2020-03-01 22:51:16 +01:00
</pre>
</div>
</div>
</div>
2020-05-26 08:40:15 +02:00
2021-01-01 20:12:34 +01:00
<div id="outline-container-weather" class="outline-2">
<h2 id="weather"><code>weather</code> - Display Weather in terminal</h2>
<div class="outline-text-2" id="text-weather">
<p>
Get the weather from <a href="http://wttr.in/">http://wttr.in/</a>.
</p>
2020-03-01 22:51:16 +01:00
<div class="org-src-container">
2020-11-03 16:27:09 +01:00
<pre class="src src-bash"><span class="org-keyword">if</span> <span class="org-rainbow-delimiters-depth-1">[</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">*</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">address</span>=<span class="org-string">"wttr.in/"</span>
<span class="org-variable-name">address</span>+=$<span class="org-variable-name">*</span>
<span class="org-keyword">else</span>
<span class="org-variable-name">address</span>=<span class="org-string">"wttr.in/"</span>
<span class="org-keyword">fi</span>
2020-05-26 08:40:15 +02:00
2020-11-03 16:27:09 +01:00
<span class="org-keyword">if </span><span class="org-builtin">type</span> sxiv &gt; /dev/null <span class="org-highlight-numbers-number">2</span>&gt;&amp;<span class="org-highlight-numbers-number">1</span>; <span class="org-keyword">then</span>
<span class="org-variable-name">address</span>+=<span class="org-string">".png"</span>
2020-05-26 08:40:15 +02:00
2020-11-03 16:27:09 +01:00
wget -qO- <span class="org-string">"</span><span class="org-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">address</span></span><span class="org-string">"</span> &gt; /tmp/weather.png &amp;&amp; <span class="org-sh-escaped-newline">\</span>
2020-05-26 08:40:15 +02:00
sxiv -b /tmp/weather.png
2020-11-03 16:27:09 +01:00
<span class="org-keyword">elif </span><span class="org-builtin">type</span> feh &gt; /dev/null <span class="org-highlight-numbers-number">2</span>&gt;&amp;<span class="org-highlight-numbers-number">1</span>; <span class="org-keyword">then</span>
<span class="org-variable-name">address</span>+=<span class="org-string">".png"</span>
2020-05-26 08:40:15 +02:00
2020-11-03 16:27:09 +01:00
wget -qO- <span class="org-string">"</span><span class="org-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">address</span></span><span class="org-string">"</span> | feh -
<span class="org-keyword">else</span>
<span class="org-type">curl</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">address</span></span><span class="org-string">"</span>
<span class="org-keyword">fi</span>
2020-03-01 22:51:16 +01:00
</pre>
</div>
</div>
</div>
2020-11-03 16:27:09 +01:00
2021-01-01 20:12:34 +01:00
<div id="outline-container-pdf2bib" class="outline-2">
<h2 id="pdf2bib"><code>pdf2bib</code> - Extract bibtex entry from PDF file</h2>
<div class="outline-text-2" id="text-pdf2bib">
2020-05-26 08:40:15 +02:00
<div class="org-src-container">
2020-11-03 16:27:09 +01:00
<pre class="src src-bash"><span class="org-function-name">pdf2doi</span> <span class="org-rainbow-delimiters-depth-1">()</span> <span class="org-rainbow-delimiters-depth-1">{</span>
pdfinfo <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">grep</span> -io <span class="org-string">"doi:.*"</span> | <span class="org-type">grep</span> -Poi <span class="org-string">"10.\d+/[^\s]+"</span> || <span class="org-sh-escaped-newline">\</span>
pdftotext <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">2</span>&gt;/dev/null - | <span class="org-type">grep</span> -io <span class="org-string">"doi:.*"</span> -m <span class="org-highlight-numbers-number">1</span> | <span class="org-type">grep</span> -Poi <span class="org-string">"10.\d+/[^\s]+"</span> || <span class="org-sh-escaped-newline">\</span>
pdftotext <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">2</span>&gt;/dev/null - | <span class="org-type">grep</span> -Poi <span class="org-string">"10.\d+/[^\s]+"</span>
<span class="org-rainbow-delimiters-depth-1">}</span>
<span class="org-function-name">doi2bib</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-type"><span class="org-comment">curl</span></span><span class="org-comment"> -LHs "Accept: application/x-bibtex" http://dx.doi.org/$1 -w "\\n"</span>
<span class="org-type">curl</span> -s <span class="org-string">"http://api.crossref.org/works/</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">/transform/application/x-bibtex"</span> -w <span class="org-string">"\\n"</span>
<span class="org-rainbow-delimiters-depth-1">}</span>
<span class="org-comment-delimiter"># </span><span class="org-comment">If a file is specified, try to extract DOI from the file</span>
<span class="org-keyword">if</span> <span class="org-rainbow-delimiters-depth-1">[</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> <span class="org-rainbow-delimiters-depth-1">]</span>; <span class="org-keyword">then</span>
<span class="org-variable-name">doi</span>=$<span class="org-rainbow-delimiters-depth-1">(</span><span class="org-sh-quoted-exec">pdf2doi</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-keyword">fi</span>
<span class="org-keyword">if </span><span class="org-builtin">hash</span> rofi <span class="org-highlight-numbers-number">2</span>&gt;/dev/null; <span class="org-keyword">then</span>
<span class="org-variable-name">doi</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">doi</span></span><span class="org-string">"</span> | rofi -i -dmenu -p <span class="org-string">"DOI"</span><span class="org-rainbow-delimiters-depth-1">)</span>
<span class="org-keyword">else</span>
<span class="org-variable-name">doi</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">doi</span></span><span class="org-string">"</span> | dmenu -i -p <span class="org-string">"DOI"</span><span class="org-rainbow-delimiters-depth-1">)</span>
<span class="org-keyword">fi</span>
<span class="org-keyword">if</span> <span class="org-rainbow-delimiters-depth-1">[</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">1</span></span><span class="org-string">"</span> <span class="org-rainbow-delimiters-depth-1">]</span>; <span class="org-keyword">then</span>
doi2bib $<span class="org-variable-name">doi</span> | xsel -ib &amp;&amp; <span class="org-sh-escaped-newline">\</span>
2022-05-09 10:05:23 +02:00
notify-send <span class="org-string">'BibTeX'</span> <span class="org-string">'Copied to Clipboard'</span> || <span class="org-sh-escaped-newline">\</span>
notify-send --urgency=critical <span class="org-string">'BibTeX'</span> <span class="org-string">'Failed'</span>
2020-11-03 16:27:09 +01:00
<span class="org-keyword">fi</span>
2020-05-26 08:40:15 +02:00
</pre>
</div>
</div>
</div>
2020-04-05 11:30:26 +02:00
2021-01-01 20:12:34 +01:00
<div id="outline-container-pdf2png" class="outline-2">
<h2 id="pdf2png"><code>pdf2png</code> - Convert a PDF to PNG</h2>
<div class="outline-text-2" id="text-pdf2png">
2020-05-26 08:40:15 +02:00
<div class="org-src-container">
2021-01-01 20:12:34 +01:00
<pre class="src src-bash"><span class="org-comment-delimiter"># </span><span class="org-comment">Check if the input argumetn is a PDF file</span>
<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-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> &amp;&amp; <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> == *.pdf <span class="org-rainbow-delimiters-depth-2">]</span><span class="org-rainbow-delimiters-depth-1">]</span>; <span class="org-keyword">then</span>
2020-11-03 16:27:09 +01:00
pdftoppm -png <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> &gt; <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-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">" | cut -f 1 -d '.' | sed 's/$/.png/')</span></span><span class="org-string">"</span>
<span class="org-keyword">fi</span>
2020-04-05 11:30:26 +02:00
</pre>
</div>
</div>
</div>
2020-11-03 16:27:09 +01:00
2021-01-01 20:12:34 +01:00
<div id="outline-container-convert-file" class="outline-2">
<h2 id="convert-file"><code>convert-file</code> - Convert any file to another filetype</h2>
<div class="outline-text-2" id="text-convert-file">
2021-10-25 14:37:10 +02:00
</div>
2022-05-09 10:05:23 +02:00
<div id="outline-container-org85b93ef" class="outline-3">
<h3 id="org85b93ef">Get basic information about the file</h3>
<div class="outline-text-3" id="text-org85b93ef">
2021-01-01 20:12:34 +01:00
<div class="org-src-container">
<pre class="src src-bash"><span class="org-comment-delimiter"># </span><span class="org-comment">Get filename</span>
<span class="org-variable-name">filename_with_extension</span>=$<span class="org-rainbow-delimiters-depth-1">(</span><span class="org-sh-quoted-exec">basename</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-comment-delimiter"># </span><span class="org-comment">Extract extension of the file</span>
<span class="org-variable-name">in_ext</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">{filename_with_extension##*.}</span></span><span class="org-string">"</span>
<span class="org-comment-delimiter"># </span><span class="org-comment">filename without extension</span>
<span class="org-variable-name">filename_without_extension</span>=$<span class="org-rainbow-delimiters-depth-1">{</span><span class="org-variable-name">filename_with_extension</span>%.*<span class="org-rainbow-delimiters-depth-1">}</span>
2021-10-25 14:37:10 +02:00
</pre>
</div>
</div>
</div>
2022-05-09 10:05:23 +02:00
<div id="outline-container-org0dbfc5e" class="outline-3">
<h3 id="org0dbfc5e">SVG files</h3>
<div class="outline-text-3" id="text-org0dbfc5e">
2021-10-25 14:37:10 +02:00
<p>
List of useful programs:
</p>
<ul class="org-ul">
<li><code>inkscape</code></li>
</ul>
</div>
2021-01-01 20:12:34 +01:00
2022-05-09 10:05:23 +02:00
<div id="outline-container-org9ba2b34" class="outline-4">
<h4 id="org9ba2b34">SVG to PNG</h4>
<div class="outline-text-4" id="text-org9ba2b34">
2021-10-25 14:37:10 +02:00
<div class="org-src-container">
<pre class="src src-bash"><span class="org-function-name">svg2png_function</span><span class="org-rainbow-delimiters-depth-1">()</span> <span class="org-rainbow-delimiters-depth-1">{</span> <span class="org-sh-escaped-newline">\</span>
<span class="org-keyword">if </span><span class="org-builtin">command</span> -v inkscape &amp;&gt; /dev/null; <span class="org-keyword">then</span>
inkscape --export-type=<span class="org-string">"</span><span class="org-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">out_ext</span></span><span class="org-string">"</span> --export-dpi=<span class="org-highlight-numbers-number">200</span> --export-area-drawing <span class="org-string">"</span><span class="org-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">filename_with_extension</span></span><span class="org-string">"</span>
<span class="org-keyword">fi</span>
<span class="org-rainbow-delimiters-depth-1">}</span>
</pre>
</div>
</div>
</div>
2022-05-09 10:05:23 +02:00
<div id="outline-container-org9fbf9f2" class="outline-4">
<h4 id="org9fbf9f2">SVG to PDF</h4>
<div class="outline-text-4" id="text-org9fbf9f2">
2021-10-25 14:37:10 +02:00
<div class="org-src-container">
<pre class="src src-bash"><span class="org-function-name">svg2pdf_function</span><span class="org-rainbow-delimiters-depth-1">()</span> <span class="org-rainbow-delimiters-depth-1">{</span> <span class="org-sh-escaped-newline">\</span>
<span class="org-keyword">if </span><span class="org-builtin">command</span> -v inkscape &amp;&gt; /dev/null; <span class="org-keyword">then</span>
inkscape --export-type=<span class="org-string">"</span><span class="org-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">out_ext</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">filename_with_extension</span></span><span class="org-string">"</span>
<span class="org-keyword">fi</span>
<span class="org-rainbow-delimiters-depth-1">}</span>
</pre>
</div>
</div>
</div>
2022-05-09 10:05:23 +02:00
<div id="outline-container-org9abaf53" class="outline-4">
<h4 id="org9abaf53">Main function</h4>
<div class="outline-text-4" id="text-org9abaf53">
2021-10-25 14:37:10 +02:00
<div class="org-src-container">
<pre class="src src-bash"><span class="org-comment-delimiter"># </span><span class="org-comment">Convert SVG Files</span>
2021-01-01 20:12:34 +01:00
<span class="org-function-name">svg2</span><span class="org-rainbow-delimiters-depth-1">()</span> <span class="org-rainbow-delimiters-depth-1">{</span> <span class="org-sh-escaped-newline">\</span>
<span class="org-variable-name">out_ext</span>=$<span class="org-rainbow-delimiters-depth-2">(</span><span class="org-sh-quoted-exec">echo</span> -e <span class="org-string">"pdf\npng"</span> | rofi -i -dmenu -p <span class="org-string">"Convert SVG to"</span><span class="org-rainbow-delimiters-depth-2">)</span>
<span class="org-keyword">if</span> <span class="org-rainbow-delimiters-depth-2">[</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">out_ext</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">exit</span>;
<span class="org-keyword">fi</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">out_ext</span></span><span class="org-string">"</span><span class="org-keyword"> in</span>
<span class="org-string">"png"</span>)
2021-10-25 14:37:10 +02:00
svg2png_function
2021-01-01 20:12:34 +01:00
;;
<span class="org-string">"pdf"</span>)
2021-10-25 14:37:10 +02:00
svg2pdf_function
2021-01-01 20:12:34 +01:00
;;
<span class="org-keyword">esac</span>
<span class="org-rainbow-delimiters-depth-1">}</span>
2021-10-25 14:37:10 +02:00
</pre>
</div>
</div>
</div>
</div>
2022-05-09 10:05:23 +02:00
<div id="outline-container-org2d81394" class="outline-3">
<h3 id="org2d81394">PDF files</h3>
<div class="outline-text-3" id="text-org2d81394">
2021-10-25 14:37:10 +02:00
<p>
List of useful programs:
</p>
<ul class="org-ul">
<li><code>pdftocairo</code></li>
<li><code>pdftoppm</code></li>
<li><code>convert</code></li>
<li><code>inkscape</code></li>
<li><code>gs</code></li>
<li><code>pdfcrop</code></li>
<li><code>pdftk</code></li>
</ul>
</div>
2022-05-09 10:05:23 +02:00
<div id="outline-container-orgaa8a2c8" class="outline-4">
<h4 id="orgaa8a2c8">PDF to PNG</h4>
<div class="outline-text-4" id="text-orgaa8a2c8">
2021-10-25 14:37:10 +02:00
<div class="org-src-container">
<pre class="src src-bash"><span class="org-function-name">pdf2png_function</span><span class="org-rainbow-delimiters-depth-1">()</span> <span class="org-rainbow-delimiters-depth-1">{</span> <span class="org-sh-escaped-newline">\</span>
<span class="org-keyword">if </span><span class="org-builtin">command</span> -v pdftocairo &amp;&gt; /dev/null; <span class="org-keyword">then</span>
pdftocairo -png -singlefile -cropbox <span class="org-string">"</span><span class="org-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">filename_with_extension</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">filename_without_extension</span></span><span class="org-string">"</span>
<span class="org-keyword">elif </span><span class="org-builtin">command</span> -v pdftoppm &amp;&gt; /dev/null; <span class="org-keyword">then</span>
pdftoppm -png <span class="org-string">"</span><span class="org-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">filename_with_extension</span></span><span class="org-string">"</span> &gt; <span class="org-string">"</span><span class="org-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">filename_without_extension</span></span><span class="org-string">.png"</span>
<span class="org-keyword">elif </span><span class="org-builtin">command</span> -v convert &amp;&gt; /dev/null; <span class="org-keyword">then</span>
convert -density <span class="org-highlight-numbers-number">100</span> -trim -antialias <span class="org-string">"</span><span class="org-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">filename_with_extension</span></span><span class="org-string">"</span> -quality <span class="org-highlight-numbers-number">100</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">filename_without_extension</span></span><span class="org-string">.png"</span>
<span class="org-keyword">elif </span><span class="org-builtin">command</span> -v inkscape &amp;&gt; /dev/null; <span class="org-keyword">then</span>
inkscape --export-type=<span class="org-string">"</span><span class="org-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">out_ext</span></span><span class="org-string">"</span> --export-dpi=<span class="org-highlight-numbers-number">200</span> --export-area-drawing <span class="org-string">"</span><span class="org-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">filename_with_extension</span></span><span class="org-string">"</span>
<span class="org-keyword">fi</span>
<span class="org-rainbow-delimiters-depth-1">}</span>
</pre>
</div>
</div>
</div>
2022-05-09 10:05:23 +02:00
<div id="outline-container-org353ac60" class="outline-4">
<h4 id="org353ac60">PDF to SVG</h4>
<div class="outline-text-4" id="text-org353ac60">
2021-10-25 14:37:10 +02:00
<div class="org-src-container">
<pre class="src src-bash"><span class="org-function-name">pdf2svg_function</span><span class="org-rainbow-delimiters-depth-1">()</span> <span class="org-rainbow-delimiters-depth-1">{</span> <span class="org-sh-escaped-newline">\</span>
<span class="org-keyword">if </span><span class="org-builtin">command</span> -v pdftocairo &amp;&gt; /dev/null; <span class="org-keyword">then</span>
pdftocairo -svg <span class="org-string">"</span><span class="org-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">filename_with_extension</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">filename_without_extension</span></span><span class="org-string">.svg"</span>
<span class="org-keyword">elif </span><span class="org-builtin">command</span> -v pdf2svg &amp;&gt; /dev/null; <span class="org-keyword">then</span>
pdf2svg <span class="org-string">"</span><span class="org-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">filename_with_extension</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">filename_without_extension</span></span><span class="org-string">.svg"</span>
<span class="org-keyword">elif </span><span class="org-builtin">command</span> -v inkscape &amp;&gt; /dev/null; <span class="org-keyword">then</span>
inkscape --export-type=<span class="org-string">"</span><span class="org-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">out_ext</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">filename_with_extension</span></span><span class="org-string">"</span>
<span class="org-keyword">fi</span>
<span class="org-rainbow-delimiters-depth-1">}</span>
</pre>
</div>
</div>
</div>
2022-05-09 10:05:23 +02:00
<div id="outline-container-orge2a8819" class="outline-4">
<h4 id="orge2a8819">PDF Reduce Size</h4>
<div class="outline-text-4" id="text-orge2a8819">
2021-10-25 14:37:10 +02:00
<div class="org-src-container">
<pre class="src src-bash"><span class="org-function-name">pdfreduce_function</span><span class="org-rainbow-delimiters-depth-1">()</span> <span class="org-rainbow-delimiters-depth-1">{</span> <span class="org-sh-escaped-newline">\</span>
<span class="org-keyword">if </span><span class="org-builtin">command</span> -v gs &amp;&gt; /dev/null; <span class="org-keyword">then</span>
<span class="org-comment-delimiter"># </span><span class="org-comment">Maybe ask for new filename?</span>
gs -sDEVICE=pdfwrite -dCompatibilityLevel=<span class="org-highlight-numbers-number">1.4</span> -dPDFSETTINGS=/printer -dNOPAUSE -dQUIET -dBATCH -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">filename_without_extension</span></span><span class="org-string">.red.pdf"</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">filename_with_extension</span></span><span class="org-string">"</span>
<span class="org-keyword">fi</span>
<span class="org-rainbow-delimiters-depth-1">}</span>
</pre>
</div>
</div>
</div>
2022-05-09 10:05:23 +02:00
<div id="outline-container-org2439e3d" class="outline-4">
<h4 id="org2439e3d">PDF Trim</h4>
<div class="outline-text-4" id="text-org2439e3d">
2021-10-25 14:37:10 +02:00
<div class="org-src-container">
<pre class="src src-bash"><span class="org-function-name">pdftrim_function</span><span class="org-rainbow-delimiters-depth-1">()</span> <span class="org-rainbow-delimiters-depth-1">{</span> <span class="org-sh-escaped-newline">\</span>
<span class="org-keyword">if </span><span class="org-builtin">command</span> -v pdfcrop &amp;&gt; /dev/null; <span class="org-keyword">then</span>
pdfcrop <span class="org-string">"</span><span class="org-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">filename_with_extension</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">filename_with_extension</span></span><span class="org-string">"</span>
<span class="org-keyword">fi</span>
<span class="org-rainbow-delimiters-depth-1">}</span>
</pre>
</div>
</div>
</div>
2022-05-09 10:05:23 +02:00
<div id="outline-container-org5cb9ddc" class="outline-4">
<h4 id="org5cb9ddc">PDF Extract Pages</h4>
<div class="outline-text-4" id="text-org5cb9ddc">
2021-10-25 14:37:10 +02:00
<div class="org-src-container">
<pre class="src src-bash"><span class="org-function-name">pdfextract_function</span><span class="org-rainbow-delimiters-depth-1">()</span> <span class="org-rainbow-delimiters-depth-1">{</span> <span class="org-sh-escaped-newline">\</span>
<span class="org-keyword">if </span><span class="org-builtin">command</span> -v pdftk &amp;&gt; /dev/null; <span class="org-keyword">then</span>
<span class="org-variable-name">pages</span>=$<span class="org-rainbow-delimiters-depth-2">(</span><span class="org-sh-quoted-exec">echo</span> -e <span class="org-string">"get first\ndelete first\nextract i-j"</span> | rofi -i -dmenu -p <span class="org-string">"Extract pages"</span><span class="org-rainbow-delimiters-depth-2">)</span>
<span class="org-keyword">if</span> <span class="org-rainbow-delimiters-depth-2">[</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">pages</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">exit</span>;
<span class="org-keyword">fi</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">pages</span></span><span class="org-string">"</span><span class="org-keyword"> in</span>
<span class="org-string">"get first"</span>)
<span class="org-keyword">if </span><span class="org-builtin">command</span> -v pdftk &amp;&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">filename_with_extension</span></span><span class="org-string">"</span> <span class="org-type">cat</span> 1-1 output <span class="org-string">"</span><span class="org-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">filename_without_extension</span></span><span class="org-string">.first.pdf"</span>
<span class="org-keyword">fi</span>
;;
<span class="org-string">"delete first"</span>)
<span class="org-keyword">if </span><span class="org-builtin">command</span> -v pdftk &amp;&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">filename_with_extension</span></span><span class="org-string">"</span> <span class="org-type">cat</span> 2-end output <span class="org-string">"</span><span class="org-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">filename_with_extension</span></span><span class="org-string">"</span>
<span class="org-keyword">fi</span>
;;
<span class="org-string">"extract i-j"</span>)
<span class="org-comment-delimiter"># </span><span class="org-comment"><span class="org-bold"><span class="org-warning">TODO</span></span></span>
<span class="org-variable-name">page_i</span>=$<span class="org-rainbow-delimiters-depth-2">(</span><span class="org-sh-quoted-exec">rofi</span> -dmenu -p <span class="org-string">"From"</span><span class="org-rainbow-delimiters-depth-2">)</span>
<span class="org-variable-name">page_j</span>=$<span class="org-rainbow-delimiters-depth-2">(</span><span class="org-sh-quoted-exec">rofi</span> -dmenu -p <span class="org-string">"To"</span><span class="org-rainbow-delimiters-depth-2">)</span>
<span class="org-keyword">if </span><span class="org-builtin">command</span> -v pdftk &amp;&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">filename_with_extension</span></span><span class="org-string">"</span> <span class="org-type">cat</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">page_i</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">page_j</span></span><span class="org-string">"</span> output <span class="org-string">"</span><span class="org-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">filename_with_extension</span></span><span class="org-string">.slice.pdf"</span>
<span class="org-keyword">fi</span>
;;
<span class="org-keyword">esac</span>
<span class="org-keyword">fi</span>
<span class="org-rainbow-delimiters-depth-1">}</span>
</pre>
</div>
</div>
</div>
2022-05-09 10:05:23 +02:00
<div id="outline-container-org6856d02" class="outline-4">
<h4 id="org6856d02">Delete First Page</h4>
<div class="outline-text-4" id="text-org6856d02">
2021-10-25 14:37:10 +02:00
<div class="org-src-container">
<pre class="src src-bash"><span class="org-function-name">pdf_delete_first_page_function</span><span class="org-rainbow-delimiters-depth-1">()</span> <span class="org-rainbow-delimiters-depth-1">{</span> <span class="org-sh-escaped-newline">\</span>
<span class="org-keyword">if </span><span class="org-builtin">command</span> -v stapler &amp;&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">filename_with_extension</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">filename_with_extension</span></span><span class="org-string">"</span>
<span class="org-keyword">elif </span><span class="org-builtin">command</span> -v pdftk &amp;&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">filename_with_extension</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">filename_with_extension</span></span><span class="org-string">"</span>
<span class="org-keyword">fi</span>
<span class="org-rainbow-delimiters-depth-1">}</span>
</pre>
</div>
</div>
</div>
2022-05-09 10:05:23 +02:00
<div id="outline-container-org2fe9680" class="outline-4">
<h4 id="org2fe9680">Remove Annotations</h4>
<div class="outline-text-4" id="text-org2fe9680">
2021-10-25 14:37:10 +02:00
<div class="org-src-container">
<pre class="src src-bash"><span class="org-function-name">pdf_remove_annotations_function</span><span class="org-rainbow-delimiters-depth-1">()</span> <span class="org-rainbow-delimiters-depth-1">{</span> <span class="org-sh-escaped-newline">\</span>
<span class="org-keyword">if </span><span class="org-builtin">command</span> -v pdftk &amp;&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">filename_with_extension</span></span><span class="org-string">"</span> output /tmp/uncompressed.pdf uncompress
<span class="org-variable-name">LANG</span>=C sed -n <span class="org-string">'/^\/Annots/!p'</span> /tmp/uncompressed.pdf &gt; /tmp/stripped.pdf
pdftk /tmp/stripped.pdf output <span class="org-string">"</span><span class="org-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">filename_with_extension</span></span><span class="org-string">"</span> compress
<span class="org-keyword">fi</span>
<span class="org-rainbow-delimiters-depth-1">}</span>
</pre>
</div>
</div>
</div>
2021-01-01 20:12:34 +01:00
2022-05-09 10:05:23 +02:00
<div id="outline-container-orgde9537c" class="outline-4">
<h4 id="orgde9537c">Main function</h4>
<div class="outline-text-4" id="text-orgde9537c">
2021-10-25 14:37:10 +02:00
<div class="org-src-container">
<pre class="src src-bash"><span class="org-comment-delimiter"># </span><span class="org-comment">Convert PDF Files</span>
2021-01-01 20:12:34 +01:00
<span class="org-function-name">pdf2</span><span class="org-rainbow-delimiters-depth-1">()</span> <span class="org-rainbow-delimiters-depth-1">{</span> <span class="org-sh-escaped-newline">\</span>
2021-10-25 14:37:10 +02:00
<span class="org-variable-name">out_ext</span>=$<span class="org-rainbow-delimiters-depth-2">(</span><span class="org-sh-quoted-exec">echo</span> -e <span class="org-string">"svg\npng\nreduce size\ntrim\nextract pages\ndelete first page\nremove annotations"</span> | rofi -i -dmenu -p <span class="org-string">"Convert PDF to"</span><span class="org-rainbow-delimiters-depth-2">)</span>
2021-01-01 20:12:34 +01:00
<span class="org-keyword">if</span> <span class="org-rainbow-delimiters-depth-2">[</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">out_ext</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">exit</span>;
<span class="org-keyword">fi</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">out_ext</span></span><span class="org-string">"</span><span class="org-keyword"> in</span>
2021-10-25 14:37:10 +02:00
<span class="org-string">"svg"</span>)
pdf2svg_function
;;
2021-01-01 20:12:34 +01:00
<span class="org-string">"png"</span>)
2021-10-25 14:37:10 +02:00
pdf2png_function
2021-01-01 20:12:34 +01:00
;;
2021-10-25 14:37:10 +02:00
<span class="org-string">"reduce size"</span>)
pdfreduce_function
2021-04-25 19:10:57 +02:00
;;
2021-10-25 14:37:10 +02:00
<span class="org-string">"trim"</span>)
pdftrim_function
;;
<span class="org-string">"extract pages"</span>)
pdfextract_function
;;
<span class="org-string">"delete first page"</span>)
pdf_delete_first_page_function
;;
<span class="org-string">"remove annotations"</span>)
pdf_remove_annotations_function
;;
<span class="org-keyword">esac</span>
<span class="org-rainbow-delimiters-depth-1">}</span>
</pre>
</div>
</div>
</div>
</div>
2022-05-09 10:05:23 +02:00
<div id="outline-container-org378402e" class="outline-3">
<h3 id="org378402e">DVI files</h3>
<div class="outline-text-3" id="text-org378402e">
2021-10-25 14:37:10 +02:00
<p>
List of useful programs:
</p>
<ul class="org-ul">
<li><code>dvisvgm</code></li>
<li><code>dvipng</code></li>
</ul>
</div>
2022-05-09 10:05:23 +02:00
<div id="outline-container-orgbc5f1ef" class="outline-4">
<h4 id="orgbc5f1ef">DVI to PNG</h4>
<div class="outline-text-4" id="text-orgbc5f1ef">
2021-10-25 14:37:10 +02:00
<div class="org-src-container">
<pre class="src src-bash"><span class="org-function-name">dvi2png_function</span><span class="org-rainbow-delimiters-depth-1">()</span> <span class="org-rainbow-delimiters-depth-1">{</span> <span class="org-sh-escaped-newline">\</span>
<span class="org-keyword">if </span><span class="org-builtin">command</span> -v dvipng &amp;&gt; /dev/null; <span class="org-keyword">then</span>
dvipng <span class="org-string">"</span><span class="org-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">filename_with_extension</span></span><span class="org-string">"</span>
<span class="org-keyword">fi</span>
<span class="org-rainbow-delimiters-depth-1">}</span>
</pre>
</div>
</div>
</div>
2022-05-09 10:05:23 +02:00
<div id="outline-container-org19c6581" class="outline-4">
<h4 id="org19c6581">DVI to SVG</h4>
<div class="outline-text-4" id="text-org19c6581">
2021-10-25 14:37:10 +02:00
<div class="org-src-container">
<pre class="src src-bash"><span class="org-function-name">dvi2svg_function</span><span class="org-rainbow-delimiters-depth-1">()</span> <span class="org-rainbow-delimiters-depth-1">{</span> <span class="org-sh-escaped-newline">\</span>
<span class="org-keyword">if </span><span class="org-builtin">command</span> -v dvisvgm &amp;&gt; /dev/null; <span class="org-keyword">then</span>
dvisvgm <span class="org-string">"</span><span class="org-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">filename_with_extension</span></span><span class="org-string">"</span> -o <span class="org-string">"</span><span class="org-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">filename_without_extension</span></span><span class="org-string">.svg"</span>
<span class="org-keyword">fi</span>
<span class="org-rainbow-delimiters-depth-1">}</span>
</pre>
</div>
</div>
</div>
2022-05-09 10:05:23 +02:00
<div id="outline-container-org8daeb8f" class="outline-4">
<h4 id="org8daeb8f">Main function</h4>
<div class="outline-text-4" id="text-org8daeb8f">
2021-10-25 14:37:10 +02:00
<div class="org-src-container">
<pre class="src src-bash"><span class="org-comment-delimiter"># </span><span class="org-comment">Convert DVI Files</span>
<span class="org-function-name">dvi2</span><span class="org-rainbow-delimiters-depth-1">()</span> <span class="org-rainbow-delimiters-depth-1">{</span> <span class="org-sh-escaped-newline">\</span>
<span class="org-variable-name">out_ext</span>=$<span class="org-rainbow-delimiters-depth-2">(</span><span class="org-sh-quoted-exec">echo</span> -e <span class="org-string">"svg\npng"</span> | rofi -i -dmenu -p <span class="org-string">"Convert DVI to"</span><span class="org-rainbow-delimiters-depth-2">)</span>
<span class="org-keyword">if</span> <span class="org-rainbow-delimiters-depth-2">[</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">out_ext</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">exit</span>;
<span class="org-keyword">fi</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">out_ext</span></span><span class="org-string">"</span><span class="org-keyword"> in</span>
2021-01-01 20:12:34 +01:00
<span class="org-string">"svg"</span>)
2021-10-25 14:37:10 +02:00
dvi2svg_function
;;
<span class="org-string">"png"</span>)
dvi2png_function
2021-01-01 20:12:34 +01:00
;;
<span class="org-keyword">esac</span>
<span class="org-rainbow-delimiters-depth-1">}</span>
2021-10-25 14:37:10 +02:00
</pre>
</div>
</div>
</div>
</div>
2021-01-01 20:12:34 +01:00
2022-05-09 10:05:23 +02:00
<div id="outline-container-orgf8bdda8" class="outline-3">
<h3 id="orgf8bdda8">DOCX/PTTX files</h3>
<div class="outline-text-3" id="text-orgf8bdda8">
2021-10-25 14:37:10 +02:00
</div>
2022-05-09 10:05:23 +02:00
<div id="outline-container-org1bbbf82" class="outline-4">
<h4 id="org1bbbf82">DOC to PDF</h4>
<div class="outline-text-4" id="text-org1bbbf82">
2021-10-25 14:37:10 +02:00
<div class="org-src-container">
<pre class="src src-bash"><span class="org-function-name">doc2pdf_function</span><span class="org-rainbow-delimiters-depth-1">()</span> <span class="org-rainbow-delimiters-depth-1">{</span> <span class="org-sh-escaped-newline">\</span>
<span class="org-keyword">if </span><span class="org-builtin">command</span> -v lowriter &amp;&gt; /dev/null; <span class="org-keyword">then</span>
lowriter --convert-to 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">filename_with_extension</span></span><span class="org-string">"</span>
<span class="org-keyword">fi</span>
<span class="org-rainbow-delimiters-depth-1">}</span>
</pre>
</div>
</div>
</div>
2022-05-09 10:05:23 +02:00
<div id="outline-container-orgdf2de45" class="outline-4">
<h4 id="orgdf2de45">Main function</h4>
<div class="outline-text-4" id="text-orgdf2de45">
2021-10-25 14:37:10 +02:00
<div class="org-src-container">
<pre class="src src-bash"><span class="org-comment-delimiter"># </span><span class="org-comment">Convert DOCX/PPTX Files</span>
2021-01-01 20:12:34 +01:00
<span class="org-function-name">docx2</span><span class="org-rainbow-delimiters-depth-1">()</span> <span class="org-rainbow-delimiters-depth-1">{</span> <span class="org-sh-escaped-newline">\</span>
<span class="org-variable-name">out_ext</span>=$<span class="org-rainbow-delimiters-depth-2">(</span><span class="org-sh-quoted-exec">echo</span> -e <span class="org-string">"pdf"</span> | rofi -i -dmenu -p <span class="org-string">"Convert DOCX/PPTX to"</span><span class="org-rainbow-delimiters-depth-2">)</span>
<span class="org-keyword">if</span> <span class="org-rainbow-delimiters-depth-2">[</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">out_ext</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">exit</span>;
<span class="org-keyword">fi</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">out_ext</span></span><span class="org-string">"</span><span class="org-keyword"> in</span>
<span class="org-string">"pdf"</span>)
2021-10-25 14:37:10 +02:00
doc2pdf_function
2021-01-01 20:12:34 +01:00
;;
<span class="org-keyword">esac</span>
<span class="org-rainbow-delimiters-depth-1">}</span>
2021-10-25 14:37:10 +02:00
</pre>
</div>
</div>
</div>
</div>
2022-05-09 10:05:23 +02:00
<div id="outline-container-org36b178e" class="outline-3">
<h3 id="org36b178e">GIF files</h3>
<div class="outline-text-3" id="text-org36b178e">
2021-10-25 14:37:10 +02:00
</div>
2022-05-09 10:05:23 +02:00
<div id="outline-container-org1e73b8e" class="outline-4">
<h4 id="org1e73b8e">GIF to PNG</h4>
<div class="outline-text-4" id="text-org1e73b8e">
2021-10-25 14:37:10 +02:00
<div class="org-src-container">
<pre class="src src-bash"><span class="org-function-name">gif2png_function</span><span class="org-rainbow-delimiters-depth-1">()</span> <span class="org-rainbow-delimiters-depth-1">{</span> <span class="org-sh-escaped-newline">\</span>
<span class="org-keyword">if </span><span class="org-builtin">command</span> -v convert &amp;&gt; /dev/null; <span class="org-keyword">then</span>
convert -coalesce <span class="org-string">"</span><span class="org-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">filename_with_extension</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">filename_without_extension</span></span><span class="org-string">.png"</span>
<span class="org-keyword">fi</span>
<span class="org-rainbow-delimiters-depth-1">}</span>
</pre>
</div>
</div>
</div>
2021-01-01 20:12:34 +01:00
2022-05-09 10:05:23 +02:00
<div id="outline-container-org8e1759c" class="outline-4">
<h4 id="org8e1759c">Main function</h4>
<div class="outline-text-4" id="text-org8e1759c">
2021-10-25 14:37:10 +02:00
<div class="org-src-container">
<pre class="src src-bash"><span class="org-comment-delimiter"># </span><span class="org-comment">Convert GIF Files</span>
2021-04-25 19:10:57 +02:00
<span class="org-function-name">gif2</span><span class="org-rainbow-delimiters-depth-1">()</span> <span class="org-rainbow-delimiters-depth-1">{</span> <span class="org-sh-escaped-newline">\</span>
<span class="org-variable-name">out_ext</span>=$<span class="org-rainbow-delimiters-depth-2">(</span><span class="org-sh-quoted-exec">echo</span> -e <span class="org-string">"png"</span> | rofi -i -dmenu -p <span class="org-string">"Convert GIF to"</span><span class="org-rainbow-delimiters-depth-2">)</span>
<span class="org-keyword">if</span> <span class="org-rainbow-delimiters-depth-2">[</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">out_ext</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">exit</span>;
<span class="org-keyword">fi</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">out_ext</span></span><span class="org-string">"</span><span class="org-keyword"> in</span>
<span class="org-string">"png"</span>)
2021-10-25 14:37:10 +02:00
gif2png_function
2021-04-25 19:10:57 +02:00
;;
<span class="org-keyword">esac</span>
<span class="org-rainbow-delimiters-depth-1">}</span>
2021-10-25 14:37:10 +02:00
</pre>
</div>
</div>
</div>
</div>
2021-04-25 19:10:57 +02:00
2022-05-09 10:05:23 +02:00
<div id="outline-container-org2554add" class="outline-3">
<h3 id="org2554add">PNG files</h3>
<div class="outline-text-3" id="text-org2554add">
2021-10-25 14:37:10 +02:00
</div>
2022-05-09 10:05:23 +02:00
<div id="outline-container-org82d3665" class="outline-4">
<h4 id="org82d3665">PNG to PDF</h4>
<div class="outline-text-4" id="text-org82d3665">
2021-10-25 14:37:10 +02:00
<div class="org-src-container">
<pre class="src src-bash"><span class="org-function-name">png2pdf_function</span><span class="org-rainbow-delimiters-depth-1">()</span> <span class="org-rainbow-delimiters-depth-1">{</span> <span class="org-sh-escaped-newline">\</span>
<span class="org-keyword">if </span><span class="org-builtin">command</span> -v convert &amp;&gt; /dev/null; <span class="org-keyword">then</span>
convert <span class="org-string">"</span><span class="org-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">filename_with_extension</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">filename_without_extension</span></span><span class="org-string">.pdf"</span>
<span class="org-keyword">fi</span>
<span class="org-rainbow-delimiters-depth-1">}</span>
</pre>
</div>
</div>
</div>
2022-05-09 10:05:23 +02:00
<div id="outline-container-org60a4f5d" class="outline-4">
<h4 id="org60a4f5d">PNG to JPG</h4>
<div class="outline-text-4" id="text-org60a4f5d">
2021-10-25 14:37:10 +02:00
<div class="org-src-container">
<pre class="src src-bash"><span class="org-function-name">png2jpg_function</span><span class="org-rainbow-delimiters-depth-1">()</span> <span class="org-rainbow-delimiters-depth-1">{</span> <span class="org-sh-escaped-newline">\</span>
<span class="org-keyword">if </span><span class="org-builtin">command</span> -v convert &amp;&gt; /dev/null; <span class="org-keyword">then</span>
convert <span class="org-string">"</span><span class="org-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">filename_with_extension</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">filename_without_extension</span></span><span class="org-string">.jpg"</span>
<span class="org-keyword">fi</span>
<span class="org-rainbow-delimiters-depth-1">}</span>
</pre>
</div>
</div>
</div>
2022-05-09 10:05:23 +02:00
<div id="outline-container-org7f202da" class="outline-4">
<h4 id="org7f202da">PNG Trim</h4>
<div class="outline-text-4" id="text-org7f202da">
2021-10-25 14:37:10 +02:00
<div class="org-src-container">
<pre class="src src-bash"><span class="org-function-name">pngtrim_function</span><span class="org-rainbow-delimiters-depth-1">()</span> <span class="org-rainbow-delimiters-depth-1">{</span> <span class="org-sh-escaped-newline">\</span>
<span class="org-keyword">if </span><span class="org-builtin">command</span> -v convert &amp;&gt; /dev/null; <span class="org-keyword">then</span>
convert -trim <span class="org-string">"</span><span class="org-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">filename_with_extension</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">filename_with_extension</span></span><span class="org-string">"</span>
<span class="org-keyword">fi</span>
<span class="org-rainbow-delimiters-depth-1">}</span>
</pre>
</div>
</div>
</div>
2022-05-09 10:05:23 +02:00
<div id="outline-container-orgedb389b" class="outline-4">
<h4 id="orgedb389b">PNG Resize</h4>
<div class="outline-text-4" id="text-orgedb389b">
2021-10-25 14:37:10 +02:00
<div class="org-src-container">
<pre class="src src-bash"><span class="org-function-name">pngresize_function</span><span class="org-rainbow-delimiters-depth-1">()</span> <span class="org-rainbow-delimiters-depth-1">{</span> <span class="org-sh-escaped-newline">\</span>
<span class="org-keyword">if </span><span class="org-builtin">command</span> -v convert &amp;&gt; /dev/null; <span class="org-keyword">then</span>
<span class="org-variable-name">size_type</span>=$<span class="org-rainbow-delimiters-depth-2">(</span><span class="org-sh-quoted-exec">echo</span> -e <span class="org-string">"width\nheight"</span> | rofi -i -dmenu -p <span class="org-string">"Maximum:"</span><span class="org-rainbow-delimiters-depth-2">)</span>
<span class="org-variable-name">size_px</span>=$<span class="org-rainbow-delimiters-depth-2">(</span><span class="org-sh-quoted-exec">rofi</span> -dmenu -p <span class="org-string">"Number of px:"</span><span class="org-rainbow-delimiters-depth-2">)</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">size_type</span></span><span class="org-string">"</span> = <span class="org-string">"width"</span> <span class="org-rainbow-delimiters-depth-2">]</span>; <span class="org-keyword">then</span>
convert -resize <span class="org-string">"</span><span class="org-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">size_px</span></span><span class="org-string">"</span>x <span class="org-string">"</span><span class="org-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">filename_with_extension</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">filename_with_extension</span></span><span class="org-string">"</span>
<span class="org-keyword">elif</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">size_type</span></span><span class="org-string">"</span> = <span class="org-string">"height"</span> <span class="org-rainbow-delimiters-depth-2">]</span>; <span class="org-keyword">then</span>
convert -resize x<span class="org-string">"</span><span class="org-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">size_px</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">filename_with_extension</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">filename_with_extension</span></span><span class="org-string">"</span>
<span class="org-keyword">fi</span>
<span class="org-keyword">fi</span>
<span class="org-rainbow-delimiters-depth-1">}</span>
</pre>
</div>
</div>
</div>
2022-05-09 10:05:23 +02:00
<div id="outline-container-orgfc606d5" class="outline-4">
<h4 id="orgfc606d5">Main function</h4>
<div class="outline-text-4" id="text-orgfc606d5">
2021-10-25 14:37:10 +02:00
<div class="org-src-container">
<pre class="src src-bash"><span class="org-comment-delimiter"># </span><span class="org-comment">Convert PNG Files</span>
2021-01-01 20:12:34 +01:00
<span class="org-function-name">png2</span><span class="org-rainbow-delimiters-depth-1">()</span> <span class="org-rainbow-delimiters-depth-1">{</span> <span class="org-sh-escaped-newline">\</span>
2021-10-25 14:37:10 +02:00
<span class="org-variable-name">out_ext</span>=$<span class="org-rainbow-delimiters-depth-2">(</span><span class="org-sh-quoted-exec">echo</span> -e <span class="org-string">"pdf\njpg\ntrim\nresize"</span> | rofi -i -dmenu -p <span class="org-string">"Convert PNG to"</span><span class="org-rainbow-delimiters-depth-2">)</span>
2021-01-01 20:12:34 +01:00
<span class="org-keyword">if</span> <span class="org-rainbow-delimiters-depth-2">[</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">out_ext</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">exit</span>;
<span class="org-keyword">fi</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">out_ext</span></span><span class="org-string">"</span><span class="org-keyword"> in</span>
<span class="org-string">"pdf"</span>)
2021-10-25 14:37:10 +02:00
png2pdf_function
;;
<span class="org-string">"jpg"</span>)
png2jpg_function
2021-01-01 20:12:34 +01:00
;;
2021-04-25 19:10:57 +02:00
<span class="org-string">"trim"</span>)
2021-10-25 14:37:10 +02:00
pngtrim_function
;;
<span class="org-string">"resize"</span>)
pngresize_function
2021-04-25 19:10:57 +02:00
;;
2021-01-01 20:12:34 +01:00
<span class="org-keyword">esac</span>
<span class="org-rainbow-delimiters-depth-1">}</span>
2021-10-25 14:37:10 +02:00
</pre>
</div>
</div>
</div>
</div>
2022-05-09 10:05:23 +02:00
<div id="outline-container-orgfa3de5c" class="outline-3">
<h3 id="orgfa3de5c">JPG files</h3>
<div class="outline-text-3" id="text-orgfa3de5c">
2021-10-25 14:37:10 +02:00
</div>
2022-05-09 10:05:23 +02:00
<div id="outline-container-orgfb74bc5" class="outline-4">
<h4 id="orgfb74bc5">JPG to PDF</h4>
<div class="outline-text-4" id="text-orgfb74bc5">
2021-10-25 14:37:10 +02:00
<div class="org-src-container">
<pre class="src src-bash"><span class="org-function-name">jpg2pdf_function</span><span class="org-rainbow-delimiters-depth-1">()</span> <span class="org-rainbow-delimiters-depth-1">{</span> <span class="org-sh-escaped-newline">\</span>
<span class="org-keyword">if </span><span class="org-builtin">command</span> -v convert &amp;&gt; /dev/null; <span class="org-keyword">then</span>
convert <span class="org-string">"</span><span class="org-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">filename_with_extension</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">filename_without_extension</span></span><span class="org-string">.pdf"</span>
<span class="org-keyword">fi</span>
<span class="org-rainbow-delimiters-depth-1">}</span>
</pre>
</div>
</div>
</div>
2022-05-09 10:05:23 +02:00
<div id="outline-container-orgb459566" class="outline-4">
<h4 id="orgb459566">JPG Resize</h4>
<div class="outline-text-4" id="text-orgb459566">
2021-10-25 14:37:10 +02:00
<div class="org-src-container">
<pre class="src src-bash"><span class="org-function-name">jpgresize_function</span><span class="org-rainbow-delimiters-depth-1">()</span> <span class="org-rainbow-delimiters-depth-1">{</span> <span class="org-sh-escaped-newline">\</span>
<span class="org-keyword">if </span><span class="org-builtin">command</span> -v convert &amp;&gt; /dev/null; <span class="org-keyword">then</span>
<span class="org-variable-name">size_type</span>=$<span class="org-rainbow-delimiters-depth-2">(</span><span class="org-sh-quoted-exec">echo</span> -e <span class="org-string">"width\nheight"</span> | rofi -i -dmenu -p <span class="org-string">"Maximum:"</span><span class="org-rainbow-delimiters-depth-2">)</span>
<span class="org-variable-name">size_px</span>=$<span class="org-rainbow-delimiters-depth-2">(</span><span class="org-sh-quoted-exec">rofi</span> -dmenu -p <span class="org-string">"Number of px:"</span><span class="org-rainbow-delimiters-depth-2">)</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">size_type</span></span><span class="org-string">"</span> = <span class="org-string">"width"</span> <span class="org-rainbow-delimiters-depth-2">]</span>; <span class="org-keyword">then</span>
convert -resize <span class="org-string">"</span><span class="org-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">size_px</span></span><span class="org-string">"</span>x <span class="org-string">"</span><span class="org-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">filename_with_extension</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">filename_with_extension</span></span><span class="org-string">"</span>
<span class="org-keyword">elif</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">size_type</span></span><span class="org-string">"</span> = <span class="org-string">"height"</span> <span class="org-rainbow-delimiters-depth-2">]</span>; <span class="org-keyword">then</span>
convert -resize x<span class="org-string">"</span><span class="org-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">size_px</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">filename_with_extension</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">filename_with_extension</span></span><span class="org-string">"</span>
<span class="org-keyword">fi</span>
<span class="org-keyword">fi</span>
<span class="org-rainbow-delimiters-depth-1">}</span>
</pre>
</div>
</div>
</div>
2021-01-01 20:12:34 +01:00
2022-05-09 10:05:23 +02:00
<div id="outline-container-orgc99bd0b" class="outline-4">
<h4 id="orgc99bd0b">Main function</h4>
<div class="outline-text-4" id="text-orgc99bd0b">
2021-10-25 14:37:10 +02:00
<div class="org-src-container">
<pre class="src src-bash"><span class="org-comment-delimiter"># </span><span class="org-comment">Convert JPG Files</span>
<span class="org-function-name">jpg2</span><span class="org-rainbow-delimiters-depth-1">()</span> <span class="org-rainbow-delimiters-depth-1">{</span> <span class="org-sh-escaped-newline">\</span>
<span class="org-variable-name">out_ext</span>=$<span class="org-rainbow-delimiters-depth-2">(</span><span class="org-sh-quoted-exec">echo</span> -e <span class="org-string">"pdf\nresize"</span> | rofi -i -dmenu -p <span class="org-string">"Convert JPG to"</span><span class="org-rainbow-delimiters-depth-2">)</span>
<span class="org-keyword">if</span> <span class="org-rainbow-delimiters-depth-2">[</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">out_ext</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">exit</span>;
<span class="org-keyword">fi</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">out_ext</span></span><span class="org-string">"</span><span class="org-keyword"> in</span>
<span class="org-string">"pdf"</span>)
jpg2pdf_function
;;
<span class="org-string">"resize"</span>)
jpgresize_function
;;
<span class="org-keyword">esac</span>
<span class="org-rainbow-delimiters-depth-1">}</span>
</pre>
</div>
</div>
</div>
</div>
2022-05-09 10:05:23 +02:00
<div id="outline-container-org1ce8f02" class="outline-3">
<h3 id="org1ce8f02">MP4 files</h3>
<div class="outline-text-3" id="text-org1ce8f02">
2021-10-25 14:37:10 +02:00
</div>
2022-05-09 10:05:23 +02:00
<div id="outline-container-orgfce3450" class="outline-4">
<h4 id="orgfce3450">MP4 to GIF</h4>
<div class="outline-text-4" id="text-orgfce3450">
2021-10-25 14:37:10 +02:00
<div class="org-src-container">
<pre class="src src-bash"><span class="org-function-name">mp42gif_function</span><span class="org-rainbow-delimiters-depth-1">()</span> <span class="org-rainbow-delimiters-depth-1">{</span> <span class="org-sh-escaped-newline">\</span>
<span class="org-keyword">if </span><span class="org-builtin">command</span> -v ffmpeg &amp;&gt; /dev/null; <span class="org-keyword">then</span>
<span class="org-variable-name">palette</span>=<span class="org-string">"/tmp/palette.png"</span>
<span class="org-variable-name">width</span>=$<span class="org-rainbow-delimiters-depth-2">(</span><span class="org-sh-quoted-exec">echo</span> -e <span class="org-string">"auto"</span> | rofi -i -dmenu -p <span class="org-string">"GIF width"</span><span class="org-rainbow-delimiters-depth-2">)</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">width</span></span><span class="org-string">"</span> = <span class="org-string">"auto"</span> <span class="org-rainbow-delimiters-depth-2">]</span>; <span class="org-keyword">then</span>
<span class="org-variable-name">filters</span>=<span class="org-string">"fps=15"</span>
<span class="org-keyword">else</span>
<span class="org-variable-name">filters</span>=<span class="org-string">"fps=15,scale=</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">:-1:flags=lanczos"</span>
<span class="org-keyword">fi</span>
<span class="org-comment-delimiter"># </span><span class="org-comment">Generate optimal pallette of colors</span>
ffmpeg -v warning -i <span class="org-string">"</span><span class="org-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">filename_with_extension</span></span><span class="org-string">"</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>
<span class="org-comment-delimiter"># </span><span class="org-comment">Convert</span>
ffmpeg -v warning -i <span class="org-string">"</span><span class="org-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">filename_with_extension</span></span><span class="org-string">"</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-string">"</span><span class="org-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">filename_without_extension</span></span><span class="org-string">.gif"</span>
<span class="org-keyword">fi</span>
<span class="org-rainbow-delimiters-depth-1">}</span>
</pre>
</div>
</div>
</div>
2022-05-09 10:05:23 +02:00
<div id="outline-container-org1ef5d98" class="outline-4">
<h4 id="org1ef5d98">Main function</h4>
<div class="outline-text-4" id="text-org1ef5d98">
2021-10-25 14:37:10 +02:00
<div class="org-src-container">
<pre class="src src-bash"><span class="org-comment-delimiter"># </span><span class="org-comment">Convert MP4 Files</span>
2021-01-01 20:12:34 +01:00
<span class="org-function-name">mp42</span><span class="org-rainbow-delimiters-depth-1">()</span> <span class="org-rainbow-delimiters-depth-1">{</span> <span class="org-sh-escaped-newline">\</span>
<span class="org-variable-name">out_ext</span>=$<span class="org-rainbow-delimiters-depth-2">(</span><span class="org-sh-quoted-exec">echo</span> -e <span class="org-string">"gif"</span> | rofi -i -dmenu -p <span class="org-string">"Convert MP4 to"</span><span class="org-rainbow-delimiters-depth-2">)</span>
<span class="org-keyword">if</span> <span class="org-rainbow-delimiters-depth-2">[</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">out_ext</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">exit</span>;
<span class="org-keyword">fi</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">out_ext</span></span><span class="org-string">"</span><span class="org-keyword"> in</span>
<span class="org-string">"gif"</span>)
2021-10-25 14:37:10 +02:00
mp42gif_function
2021-01-01 20:12:34 +01:00
;;
<span class="org-keyword">esac</span>
<span class="org-rainbow-delimiters-depth-1">}</span>
2021-10-25 14:37:10 +02:00
</pre>
</div>
</div>
</div>
</div>
2021-01-01 20:12:34 +01:00
2022-05-09 10:05:23 +02:00
<div id="outline-container-orgd348c43" class="outline-3">
<h3 id="orgd348c43">Case statement</h3>
<div class="outline-text-3" id="text-orgd348c43">
<div class="org-src-container">
<pre class="src src-bash"><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">in_ext</span></span><span class="org-string">"</span><span class="org-keyword"> in</span>
<span class="org-string">"svg"</span>)
svg2
;;
<span class="org-string">"gif"</span>)
gif2
;;
<span class="org-string">"dvi"</span>)
dvi2
;;
<span class="org-string">"pdf"</span>)
pdf2
;;
<span class="org-string">"mp4"</span>)
mp42
;;
<span class="org-string">"png"</span>)
png2
;;
<span class="org-string">"jpg"</span>)
jpg2
;;
<span class="org-string">"jpeg"</span>)
jpg2
;;
<span class="org-string">"docx"</span>)
docx2
;;
<span class="org-string">"pttx"</span>)
docx2
;;
<span class="org-keyword">esac</span>
</pre>
</div>
</div>
</div>
</div>
<div id="outline-container-preview-file" class="outline-2">
<h2 id="preview-file"><code>preview-file</code> - Preview any file</h2>
<div class="outline-text-2" id="text-preview-file">
</div>
<div id="outline-container-orgf5dc56d" class="outline-3">
<h3 id="orgf5dc56d">Get basic information about the file</h3>
<div class="outline-text-3" id="text-orgf5dc56d">
<div class="org-src-container">
<pre class="src src-bash"><span class="org-comment-delimiter"># </span><span class="org-comment">Get filename</span>
<span class="org-variable-name">filename_with_extension</span>=$<span class="org-rainbow-delimiters-depth-1">(</span><span class="org-sh-quoted-exec">basename</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-comment-delimiter"># </span><span class="org-comment">Extract extension of the file</span>
<span class="org-variable-name">in_ext</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">{filename_with_extension##*.}</span></span><span class="org-string">"</span>
<span class="org-comment-delimiter"># </span><span class="org-comment">filename without extension</span>
<span class="org-variable-name">filename_without_extension</span>=$<span class="org-rainbow-delimiters-depth-1">{</span><span class="org-variable-name">filename_with_extension</span>%.*<span class="org-rainbow-delimiters-depth-1">}</span>
</pre>
</div>
</div>
</div>
<div id="outline-container-org388aa4c" class="outline-3">
<h3 id="org388aa4c">SVG files</h3>
<div class="outline-text-3" id="text-org388aa4c">
<div class="org-src-container">
<pre class="src src-bash"><span class="org-comment-delimiter"># </span><span class="org-comment">Convert SVG Files</span>
<span class="org-function-name">svg2</span><span class="org-rainbow-delimiters-depth-1">()</span> <span class="org-rainbow-delimiters-depth-1">{</span> <span class="org-sh-escaped-newline">\</span>
<span class="org-keyword">if </span><span class="org-builtin">command</span> -v inkscape &amp;&gt; /dev/null; <span class="org-keyword">then</span>
inkscape --export-type=<span class="org-string">"</span><span class="org-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">out_ext</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">filename_with_extension</span></span><span class="org-string">"</span> --export-filename=<span class="org-string">"/tmp/</span><span class="org-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">filename_without_extension</span></span><span class="org-string">.pdf"</span> &amp;&amp; zathura <span class="org-string">"/tmp/</span><span class="org-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">filename_without_extension</span></span><span class="org-string">.pdf"</span>
<span class="org-keyword">fi</span>
<span class="org-rainbow-delimiters-depth-1">}</span>
</pre>
</div>
</div>
</div>
<div id="outline-container-orga4584da" class="outline-3">
<h3 id="orga4584da">DOCX files</h3>
<div class="outline-text-3" id="text-orga4584da">
<div class="org-src-container">
<pre class="src src-bash"><span class="org-comment-delimiter"># </span><span class="org-comment">Convert DOCX/PPTX Files</span>
<span class="org-function-name">docx2</span><span class="org-rainbow-delimiters-depth-1">()</span> <span class="org-rainbow-delimiters-depth-1">{</span> <span class="org-sh-escaped-newline">\</span>
<span class="org-keyword">if </span><span class="org-builtin">command</span> -v lowriter &amp;&gt; /dev/null; <span class="org-keyword">then</span>
lowriter --convert-to 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">filename_with_extension</span></span><span class="org-string">"</span> --outdir /tmp/ &amp;&amp; zathura <span class="org-string">"/tmp/</span><span class="org-string"><span class="org-constant">$</span></span><span class="org-string"><span class="org-variable-name">filename_without_extension</span></span><span class="org-string">.pdf"</span>
<span class="org-keyword">fi</span>
<span class="org-rainbow-delimiters-depth-1">}</span>
</pre>
</div>
</div>
</div>
<div id="outline-container-org4a60199" class="outline-3">
<h3 id="org4a60199">Case statement</h3>
<div class="outline-text-3" id="text-org4a60199">
2021-10-25 14:37:10 +02:00
<div class="org-src-container">
<pre class="src src-bash"><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">in_ext</span></span><span class="org-string">"</span><span class="org-keyword"> in</span>
2021-01-01 20:12:34 +01:00
<span class="org-string">"svg"</span>)
svg2
;;
2021-04-25 19:10:57 +02:00
<span class="org-string">"gif"</span>)
gif2
;;
2021-10-25 14:37:10 +02:00
<span class="org-string">"dvi"</span>)
dvi2
;;
2021-01-01 20:12:34 +01:00
<span class="org-string">"pdf"</span>)
pdf2
;;
<span class="org-string">"mp4"</span>)
mp42
;;
<span class="org-string">"png"</span>)
png2
;;
2021-10-25 14:37:10 +02:00
<span class="org-string">"jpg"</span>)
jpg2
;;
<span class="org-string">"jpeg"</span>)
jpg2
;;
2021-01-01 20:12:34 +01:00
<span class="org-string">"docx"</span>)
docx2
;;
<span class="org-string">"pttx"</span>)
docx2
;;
<span class="org-keyword">esac</span>
</pre>
</div>
</div>
</div>
2021-10-25 14:37:10 +02:00
</div>
2021-01-01 20:12:34 +01:00
<div id="outline-container-pdf-shrink" class="outline-2">
<h2 id="pdf-shrink"><code>pdf-shrink</code> - Pdf Shrink</h2>
<div class="outline-text-2" id="text-pdf-shrink">
<p>
Simply reduces the size of a given pdf file.
</p>
2020-04-05 11:30:26 +02:00
<div class="org-src-container">
2020-11-03 16:27:09 +01:00
<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>
2021-01-01 20:12:34 +01:00
<span class="org-comment-delimiter"># </span><span class="org-comment">Output resolution defaults to 90 unless given:</span>
2020-11-03 16:27:09 +01:00
<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>
2020-04-05 11:30:26 +02:00
</pre>
</div>
</div>
</div>
2021-01-01 20:12:34 +01:00
<div id="outline-container-pdf-delete-annotations" class="outline-2">
<h2 id="pdf-delete-annotations"><code>pdf-delete-annotations</code> - Delete Annotations from PDFs</h2>
<div class="outline-text-2" id="text-pdf-delete-annotations">
2020-05-26 08:40:15 +02:00
<p>
2021-01-01 20:12:34 +01:00
Taken from this <a href="https://gist.github.com/stefanschmidt/5248592">gist</a>.
2020-05-26 08:40:15 +02:00
</p>
2020-04-05 11:30:26 +02:00
<div class="org-src-container">
2021-01-01 20:12:34 +01:00
<pre class="src src-bash"><span class="org-comment-delimiter"># </span><span class="org-comment">Check if the input argumetn is a PDF file</span>
<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-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> &amp;&amp; <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> == *.pdf <span class="org-rainbow-delimiters-depth-2">]</span><span class="org-rainbow-delimiters-depth-1">]</span>; <span class="org-keyword">then</span>
pdftk $<span class="org-highlight-numbers-number">1</span> output /tmp/uncompressed.pdf uncompress
<span class="org-variable-name">LANG</span>=C sed -n <span class="org-string">'/^\/Annots/!p'</span> /tmp/uncompressed.pdf &gt; /tmp/stripped.pdf
pdftk /tmp/stripped.pdf output $<span class="org-highlight-numbers-number">1</span> compress
<span class="org-keyword">fi</span>
2020-05-26 08:40:15 +02:00
</pre>
</div>
</div>
</div>
2020-04-05 11:30:26 +02:00
2021-01-01 20:12:34 +01:00
<div id="outline-container-pdf-delete-first-page" class="outline-2">
<h2 id="pdf-delete-first-page"><code>pdf-delete-first-page</code> - Delete first page of PDF</h2>
<div class="outline-text-2" id="text-pdf-delete-first-page">
2020-05-26 08:40:15 +02:00
<p>
The requirement is to have <code>pdftk</code> or <code>stapler</code> installed.
</p>
2020-04-05 11:30:26 +02:00
2020-05-26 08:40:15 +02:00
<div class="org-src-container">
2021-01-01 20:12:34 +01:00
<pre class="src src-bash"><span class="org-comment-delimiter"># </span><span class="org-comment">Check if the input argumetn is a PDF file</span>
<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>
2020-11-03 16:27:09 +01:00
<span class="org-keyword">if </span><span class="org-builtin">type</span> stapler &gt; /dev/null <span class="org-highlight-numbers-number">2</span>&gt;&amp;<span class="org-highlight-numbers-number">1</span>; <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-highlight-numbers-number">2</span>&gt;&amp;<span class="org-highlight-numbers-number">1</span>; <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>
2021-01-01 20:12:34 +01:00
<div id="outline-container-rofi-calc" class="outline-2">
<h2 id="rofi-calc"><code>rofi-calc</code> - Simple Calculation using Rofi</h2>
<div class="outline-text-2" id="text-rofi-calc">
<p>
Run some simple calculations with <code>rofi</code>.
</p>
2020-11-03 16:27:09 +01:00
<div class="org-src-container">
<pre class="src src-bash">rofi -show calc -mode calc -no-show-match -no-sort
</pre>
</div>
</div>
</div>
2021-01-01 20:12:34 +01:00
<div id="outline-container-pass-gen" class="outline-2">
<h2 id="pass-gen"><code>pass-gen</code> - Generate Random Alphanumeric Password</h2>
<div class="outline-text-2" id="text-pass-gen">
2020-11-03 16:27:09 +01:00
<div class="org-src-container">
2021-01-01 20:12:34 +01:00
<pre class="src src-bash"><span class="org-comment-delimiter"># </span><span class="org-comment">Ask for the wanted number of caracters</span>
<span class="org-variable-name">num</span>=$<span class="org-rainbow-delimiters-depth-1">(</span><span class="org-sh-quoted-exec">rofi</span> -dmenu -p <span class="org-string">"Number of caracters"</span><span class="org-rainbow-delimiters-depth-1">)</span>
<span class="org-comment-delimiter"># </span><span class="org-comment">Random generation of alphanumeric caracters</span>
2020-11-03 16:27:09 +01:00
<span class="org-variable-name">pass</span>=$<span class="org-rainbow-delimiters-depth-1">(</span><span class="org-sh-quoted-exec">cat</span> /dev/urandom | tr -dc <span class="org-string">'a-zA-Z0-9'</span> | fold -w <span class="org-highlight-numbers-number">32</span> | head -n <span class="org-highlight-numbers-number">1</span><span class="org-rainbow-delimiters-depth-1">)</span>
<span class="org-variable-name">re</span>=<span class="org-string">'^[0-9]+$'</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">num</span> =~ $<span class="org-variable-name">re</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-variable-name">pass</span>=$<span class="org-rainbow-delimiters-depth-1">{</span><span class="org-variable-name">pass</span>:0:$<span class="org-variable-name">num</span><span class="org-rainbow-delimiters-depth-1">}</span>
<span class="org-keyword">fi</span>
2021-01-01 20:12:34 +01:00
<span class="org-comment-delimiter"># </span><span class="org-comment">Send the password to the clipboard</span>
2020-11-03 16:27:09 +01:00
<span class="org-builtin">printf</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">pass</span></span><span class="org-string">"</span> | xclip -sel clip &amp;&amp; <span class="org-sh-escaped-newline">\</span>
2022-05-09 10:05:23 +02:00
notify-send <span class="org-string">'Password'</span> <span class="org-string">'Generated'</span>
2020-04-05 11:30:26 +02:00
</pre>
</div>
</div>
</div>
2021-01-01 20:12:34 +01:00
<div id="outline-container-sxhkd-help" class="outline-2">
<h2 id="sxhkd-help"><code>sxhkd-help</code> - List of keybindings using Rofi</h2>
<div class="outline-text-2" id="text-sxhkd-help">
<div class="org-src-container">
<pre class="src src-bash">awk <span class="org-string">'/^[a-z]/ &amp;&amp; last {print "&lt;small&gt;",$0,"\t",last,"&lt;/small&gt;"} {last=""} /^#/{last=$0}'</span> ~/.config/sxhkd/sxhkdrc<span class="org-rainbow-delimiters-depth-1">{</span>,.i3<span class="org-rainbow-delimiters-depth-1">}</span> |
column -t -s $<span class="org-string">'\t'</span> |
rofi -dmenu -i -markup-rows -no-show-icons -width <span class="org-highlight-numbers-number">1000</span> -lines <span class="org-highlight-numbers-number">15</span> -yoffset <span class="org-highlight-numbers-number">40</span>
</pre>
</div>
</div>
</div>
2020-01-11 22:04:45 +01:00
</div>
<div id="postamble" class="status">
<p class="author">Author: Dehaeze Thomas</p>
2022-05-09 10:05:23 +02:00
<p class="date">Created: 2022-05-09 lun. 10:04</p>
2020-01-11 22:04:45 +01:00
</div>
</body>
</html>