literate-dotfiles/docs/binaries.html
2020-05-26 08:40:15 +02:00

1064 lines
33 KiB
HTML

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<!-- 2020-05-26 mar. 08:39 -->
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>Binaries</title>
<meta name="generator" content="Org mode" />
<meta name="author" content="Dehaeze Thomas" />
<link rel="stylesheet" type="text/css" href="./css/htmlize.css"/>
<link rel="stylesheet" type="text/css" href="./css/readtheorg.css"/>
<script type="text/javascript" src="./js/jquery.min.js"></script>
<script type="text/javascript" src="./js/bootstrap.min.js"></script>
<script type="text/javascript" src="./js/jquery.stickytableheaders.min.js"></script>
<script type="text/javascript" src="./js/readtheorg.js"></script>
</head>
<body>
<div id="org-div-home-and-up">
<a accesskey="h" href="./index.html"> UP </a>
|
<a accesskey="H" href="./index.html"> HOME </a>
</div><div id="content">
<h1 class="title">Binaries</h1>
<div id="table-of-contents">
<h2>Table of Contents</h2>
<div id="text-table-of-contents">
<ul>
<li><a href="#org28d68eb"><code>displayselect</code> - Select Screen</a></li>
<li><a href="#orgd951db9"><code>vpntoggle</code> - Connect to VPN using NordVPN</a></li>
<li><a href="#org39f3bdf"><code>bukurun</code> - Open link from Buku</a></li>
<li><a href="#org1ce653d"><code>i3exit</code> - Manage lock, suspend, reboot, &#x2026;</a></li>
<li><a href="#org91bab59"><code>askpass-rofi</code> - GUI prompt for passwords</a></li>
<li><a href="#org2d85447"><code>screenshot</code> - Take Screenshot</a></li>
<li><a href="#org8a00ba3"><code>network-toggle</code> - Toggle Network</a></li>
<li><a href="#orgd568e72"><code>make-gif</code> - Make GIF</a></li>
<li><a href="#orgd7e49ff"><code>yt-audio</code> - Download-Audio from youtube</a></li>
<li><a href="#org89810de"><code>yt-video</code> - Download-Video from youtube</a></li>
<li><a href="#org539efcb"><code>setbg</code> - Set Background</a></li>
<li><a href="#org229006d"><code>insert-unicode</code> - Insert Unicode Icon</a></li>
<li><a href="#orgf4064e2"><code>insert-nerd-fonts</code> - Insert Nerd Font Icon</a></li>
<li><a href="#org2796c9b"><code>linkhandler</code> - Open with Default application</a></li>
<li><a href="#org56e0cc2"><code>lockscreen</code> - LockScreen</a></li>
<li><a href="#orgbe881e3"><code>mopidy-restart</code> - Restart Mopidy</a></li>
<li><a href="#orgffe5d25"><code>upload</code> - Upload Script</a></li>
<li><a href="#orgcd16f91"><code>weather</code> - Display Weather in terminal</a></li>
<li><a href="#org17ef4d2"><code>readbib</code> - Open Bibliography File</a></li>
<li><a href="#orgda667bb"><code>readnotes</code> - Open Note File</a></li>
<li><a href="#orge45135c"><code>pdf2bib</code> - Extract bibtex entry from PDF file</a></li>
<li><a href="#org70ec456"><code>pdf2png</code> - Convert a PDF to PNG</a></li>
<li><a href="#org7601ca9"><code>pdf-shrink</code> - Pdf Shrink</a></li>
<li><a href="#org4041717"><code>pdf-delete-annotations</code> - Delete Annotations from PDFs</a></li>
<li><a href="#orge18f381"><code>pdf-delete-first-page</code> - Delete first page of PDF</a></li>
</ul>
</div>
</div>
<div id="outline-container-org28d68eb" class="outline-2">
<h2 id="org28d68eb"><code>displayselect</code> - Select Screen</h2>
<div class="outline-text-2" id="text-org28d68eb">
<p>
Script taken from Luke Smith.
</p>
<div class="org-src-container">
<pre class="src src-bash">twoscreen() { # If multi-monitor is selected and there are two screens.
mirror=$(printf "no\\nyes" | dmenu -i -p "Mirror displays?")
# Mirror displays using native resolution of external display and a scaled
# version for the internal display
if [ "$mirror" = "yes" ]; then
external=$(echo "$screens" | dmenu -i -p "Optimize resolution for:")
internal=$(echo "$screens" | grep -v "$external")
res_external=$(xrandr --query | sed -n "/^$external/,/\+/p" | \
tail -n 1 | awk '{print $1}')
res_internal=$(xrandr --query | sed -n "/^$internal/,/\+/p" | \
tail -n 1 | awk '{print $1}')
res_ext_x=$(echo $res_external | sed 's/x.*//')
res_ext_y=$(echo $res_external | sed 's/.*x//')
res_int_x=$(echo $res_internal | sed 's/x.*//')
res_int_y=$(echo $res_internal | sed 's/.*x//')
scale_x=$(echo "$res_ext_x / $res_int_x" | bc -l)
scale_y=$(echo "$res_ext_y / $res_int_y" | bc -l)
xrandr --output "$external" --auto --scale 1.0x1.0 \
--output "$internal" --auto --same-as "$external" \
--scale "$scale_x"x"$scale_y"
else
primary=$(echo "$screens" | dmenu -i -p "Select primary display:")
secondary=$(echo "$screens" | grep -v "$primary")
direction=$(printf "left\\nright" | dmenu -i -p "What side of $primary should $secondary be on?")
xrandr --output "$primary" --auto --scale 1.0x1.0 --output "$secondary" --"$direction"-of "$primary" --auto --scale 1.0x1.0
fi
}
morescreen() { # If multi-monitor is selected and there are more than two screens.
primary=$(echo "$screens" | dmenu -i -p "Select primary display:")
secondary=$(echo "$screens" | grep -v "$primary" | dmenu -i -p "Select secondary display:")
direction=$(printf "left\\nright" | dmenu -i -p "What side of $primary should $secondary be on?")
tertiary=$(echo "$screens" | grep -v "$primary" | grep -v "$secondary" | dmenu -i -p "Select third display:")
xrandr --output "$primary" --auto --output "$secondary" --"$direction"-of "$primary" --auto --output "$tertiary" --"$(printf "left\\nright" | grep -v "$direction")"-of "$primary" --auto
}
multimon() { # Multi-monitor handler.
case "$(echo "$screens" | wc -l)" in
1) xrandr $(echo "$allposs" | grep -v "$screens" | awk '{print "--output", $1, "--off"}' | tr '\n' ' ') ;;
2) twoscreen ;;
*) morescreen ;;
esac ;}
# Get all possible displays
allposs=$(xrandr -q | grep "connected")
# Get all connected screens.
screens=$(echo "$allposs" | grep " connected" | awk '{print $1}')
# Get user choice including multi-monitor and manual selection:
chosen=$(printf "%s\\ncancel\\nmulti-monitor\\nmanual selection" "$screens" | dmenu -i -p "Select display arangement:") &amp;&amp;
case "$chosen" in
"cancel") exit ;;
"manual selection") arandr ; exit ;;
"multi-monitor") multimon ;;
*) xrandr --output "$chosen" --auto --scale 1.0x1.0 $(echo "$allposs" | grep -v "$chosen" | awk '{print "--output", $1, "--off"}' | tr '\n' ' ') ;;
esac
$HOME/.config/polybar/scripts/launch.sh # restart polybar
pgrep -x dunst &gt;/dev/null &amp;&amp; killall dunst &amp;&amp; setsid dunst &amp; # Restart dunst to ensure proper location on screen
</pre>
</div>
</div>
</div>
<div id="outline-container-orgd951db9" class="outline-2">
<h2 id="orgd951db9"><code>vpntoggle</code> - Connect to VPN using NordVPN</h2>
<div class="outline-text-2" id="text-orgd951db9">
<div class="org-src-container">
<pre class="src src-bash">if [[ $(nordvpn status) == *"Connected"* ]]; then
nordvpn disconnect &amp;&amp; dunstify --replace=23198 "VPN" "Disconnected";
else
country=`cat ~/.local/data/nordvpn_countries.txt | sed 's/\s*\t\s*/ /g ; s/\s/\n/g ; s/_/ /g ; /^[a-zA-Z]/!d ; s/\(.*\)/\L\1/' | rofi -i -dmenu | sed 's/\s/_/g'`;
dunstify --replace=23198 "VPN" "Connecting to $country...";
nordvpn connect $country &amp;&amp; dunstify --replace=23198 "VPN" "Connected to $country";
fi
</pre>
</div>
</div>
</div>
<div id="outline-container-org39f3bdf" class="outline-2">
<h2 id="org39f3bdf"><code>bukurun</code> - Open link from Buku</h2>
<div class="outline-text-2" id="text-org39f3bdf">
<div class="org-src-container">
<pre class="src src-bash">_rofi () {
rofi -dmenu -i -no-levenshtein-sort -width 1000 "$@"
}
# display settings
display_type=1
max_str_width=80
# keybindings
switch_view="Alt+Tab"
new_bookmark="Alt+n"
actions="Alt+a"
edit="Alt+e"
delete="Alt+d"
# colors
help_color="#334433"
# source global config
if [[ -f /etc/buku_run.config ]]
then
source /etc/buku_run.config
fi
# source local config:
if [[ -z $XDG_CONFIG_DIR ]]
then
if [[ -f $HOME/.config/buku_run/config ]]
then
source $HOME/.config/buku_run/config
else
echo "User config file \'~/.config/buku_run/config\' not found. using global config"
fi
else
if [[ -f "${XDG_CONFIG_DIR}/buku_run/config" ]]
then
source "${XDG_CONFIG_DIR}/buku_run/config"
else
echo "User config file \'~/.config/buku_run/config\' not found. using global config"
fi
fi
main () {
HELP="Welcome to Buku. Use &lt;span color='${help_color}'&gt;${new_bookmark}&lt;/span&gt; to add a new Bookmark
Use &lt;span color='${help_color}'&gt;${switch_view}&lt;/span&gt; to switch View. &lt;span color='${help_color}'&gt;${actions}&lt;/span&gt; for actions"
if [[ $mode == "bookmarks" ]]; then
content=$(parseBuku)
menu=$(echo "${content}" | _rofi -p '&gt; ' -filter "${filter}" -mesg "${HELP}" -kb-custom-1 "${new_bookmark}" -kb-custom-2 "${switch_view}" -kb-custom-3 "${actions}" -kb-custom-4 "${edit}" -kb-custom-5 "${delete}")
elif [[ $mode == "tags" ]]; then
menu=$(buku --np --st | awk '{$NF=""; print $0}' | cut -d ' ' -f2- | _rofi -p '&gt; ' -mesg "${HELP}" -kb-custom-1 "${new_bookmark}" -kb-custom-2 "${switch_view}" -kb-custom-3 "${actions}" -kb-custom-4 "${edit}" -kb-custom-5 "${delete}")
fi
val=$?
if [[ $val -eq 1 ]]; then
exit
elif [[ $val -eq 12 ]]; then
optionsMenu
elif [[ $val -eq 10 ]]; then
addMark
elif [[ $val -eq 14 ]]; then
deleteMenu
elif [[ $val -eq 13 ]]; then
editMenu
elif [[ $val -eq 11 ]]; then
if [[ $mode == "bookmarks" ]]; then
export mode="tags"
mode=tags main
elif [[ $mode == "tags" ]]; then
export mode="bookmarks"
mode=bookmarks main
fi
elif [[ $val -eq 0 ]]; then
if [[ $mode == "bookmarks" ]]; then
id=$(getId "$content" "$menu")
for bm in ${id}; do
buku -o "${bm}"
done
elif [[ $mode == "tags" ]]; then
filter="${menu}" mode="bookmarks" main
fi
fi
}
optionsMenu () {
if [[ $mode == "bookmarks" ]]; then
askmenu=$(echo -e "&lt; Return\n---\n1. Edit\n2. Delete" | _rofi -p '&gt; ' -mesg "Choose Action for bookmark")
val=$?
if [[ $val -eq 1 ]]; then
exit
elif [[ $val -eq 0 ]]; then
if [[ $askmenu == "&lt; Return" ]]; then
export mode=bookmarks
main
elif [[ $askmenu == "1. Edit" ]]; then
editMenu
elif [[ $askmenu == "2. Delete" ]]; then
deleteMenu
fi
fi
elif [[ $mode == "tags" ]]; then
askmenu=$(echo -e "&lt; Return\n---\n1. Replace Tag\n2. Delete Tag" | _rofi -p '&gt; ' -mesg "Choose Action for tag \"${menu}\"")
val=$?
if [[ $val -eq 1 ]]; then
exit
elif [[ $val -eq 0 ]]; then
if [[ $askmenu == "&lt; Return" ]]; then
export mode=tags
main
elif [[ $askmenu == "1. Replace Tag" ]]; then
newtag=$(echo | _rofi -p '&gt; ' -mesg "Enter new tag name for tag \"${menu}\"")
val=$?
if [[ $val -eq 1 ]]; then
exit
elif [[ $val -eq 0 ]]; then
if [[ $newtag == "" ]]; then
mode=tags main
else
buku -r "${menu}" "${newtag}"
mode=tags main
fi
fi
elif [[ $askmenu == "2. Delete Tag" ]]; then
delask=$(echo -e "1. Yes\n2. No" | _rofi -p '&gt; ' -mesg "Really delete tag?")
val=$?
if [[ $val -eq 1 ]]; then
exit
elif [[ $val -eq 0 ]]; then
if [[ $delask == "1. Yes" ]]; then
buku -r "${menu}"
mode=tags main
elif [[ $delask == "2. No" ]]; then
mode=tags main
fi
fi
fi
fi
fi
}
deleteMenu () {
id=$(getId "$content" "$menu")
delask=$(echo -e "1. Yes\n2. No" | _rofi -p '&gt; ' -mesg "Really delete bookmark?")
val=$?
if [[ $val -eq 1 ]]; then
exit
elif [[ $val -eq 0 ]]; then
if [[ $delask == "1. Yes" ]]; then
buku -d ${id} --tacit
mode=bookmarks main
elif [[ $delask == "2. No" ]]; then
optionsMenu
fi
fi
}
editMenu () {
id=$(getId "$content" "$menu")
title="$(getTitleFromId $id)"
bookmark="$(getUrlFromId $id)"
tags="$(getTagsFromId $id)"
content=$(echo -e "1. title: $title\n2. url: $bookmark\n3. tags: $tags")
editmenu=$(echo -e "&lt; Return\n---\n${content}" | _rofi -p '&gt; ')
val=$?
if [[ $val -eq 1 ]]; then
exit
elif [[ $val -eq 0 ]]; then
if [[ $editmenu == "&lt; Return" ]]; then
main
elif [[ $editmenu == "tags: NOTAG" ]]; then
addTags --update
elif [[ $editmenu =~ tags:* ]]; then
tags="${tags}" editTags
elif [[ $editmenu =~ url:* ]]; then
editBookmark
elif [[ $editmenu =~ title:* ]]; then
editTitle
fi
fi
}
editTags () {
edittagsmenu=$(echo | _rofi -filter "${tags}" -p '&gt; ' -mesg "Edit Tags and hit Enter")
val=$?
if [[ $val -eq 1 ]]; then
exit
elif [[ $val -eq 0 ]]; then
buku -u ${id} --tag "${edittagsmenu}"
fi
mode=bookmarks main
}
editBookmark () {
bmarkmenu=$(echo "" | _rofi -p "&gt; " -filter "${bookmark}" -mesg "Edit Bookmark and hit Enter")
val=$?
if [[ $val -eq 1 ]]; then
exit
elif [[ $val -eq 0 ]]; then
if [[ $bmarkmenu == "http"* ]]; then
buku -u "${id}" --url "${bmarkmenu}"
else
echo "" | rofi -e "Not a valid URI, Make sure URLs start with http"
editBookmark
fi
fi
mode=bookmarks main
}
editTitle () {
titlemenu=$(echo "" | _rofi -p "&gt; " -filter "${title}" -mesg "Edit Title and hit Enter")
val=$?
if [[ $val -eq 1 ]]; then
exit
elif [[ $val -eq 0 ]]; then
buku -u "${id}" --title "${titlemenu}"
fi
mode=bookmarks main
}
addMark () {
inserturl=$(echo -e "$(xclip -o)" | _rofi -p '&gt; ' -mesg "Use URL below or type manually")
val=$?
if [[ $val -eq 1 ]]; then
exit
elif [[ $val -eq 0 ]]; then
addTags
fi
}
addTags () {
inserttags=$(buku --np --st | awk '{$NF=""; print $0}' | cut -d ' ' -f2- | _rofi -p '&gt; ' -mesg "Add some tags. Separate tags with ', '")
val=$?
if [[ $val -eq 1 ]]; then
exit
elif [[ $val -eq 0 ]]; then
if [[ $(echo "${inserttags}" | wc -l) -gt 1 ]]; then
taglist=$(echo "${inserttags}" | tr '\n' ',')
tags=()
for tag in $taglist; do
tags+=("$tag")
done
else
tags=${inserttags}
fi
if [[ $1 == "--update" ]]; then
buku -u "${id}" --tag ${tags}
else
buku -a ${inserturl} ${tags}
fi
fi
}
parseBuku () {
echo "$(buku --nc -p | gawk -v max="$max_str_width" -v type="$display_type" '
BEGIN {
RS=""
FS="\n"
}
{
if ($3 == "")
$3 = " # NOTAG"
id = gensub(/([0-9]+)\.(.*)/, "\\1", "g", $1)
url = substr(gensub(/\s+&gt; (.*)/, "\\1", "g", $2),0,max)
tags = gensub(/\s+# (.*)/, "\\1", "g", $3)
title = substr(gensub(/[0-9]+\.\s*(.*)/, "\\1", "g", $1),0,max)
if (type == 1)
print id "\t" url "\t" tags
else
print id "\t" title "\t" tags
if (type == 3)
print " \t" url "\t "
print ""
}
' | column -t -s $'\t')"
}
getId () {
id=$(echo "${2%% *}")
if [ -z "$id" ]; then
prev=""
IFS=$'\n'
for line in $1; do
if [ "$2" = "$line" ]; then
id=$(echo "${prev%% *}")
break
else
prev="$line"
fi
done
fi
echo $id
}
getTitleFromId () {
echo "$(buku --nc -p $1 | gawk '
BEGIN {
RS=""
FS="\n"
}
{
print gensub(/[0-9]+\.\s*(.*)/, "\\1", "g", $1)
}
')"
}
getUrlFromId () {
echo "$(buku --nc -p $1 | gawk '
BEGIN {
RS=""
FS="\n"
}
{
print gensub(/\s+&gt; (.*)/, "\\1", "g", $2)
}
')"
}
getTagsFromId () {
echo "$(buku --nc -p $1 | gawk '
BEGIN {
RS=""
FS="\n"
}
{
print gensub(/\s+# (.*)/, "\\1", "g", $3)
}
')"
}
mode=bookmarks main
</pre>
</div>
</div>
</div>
<div id="outline-container-org1ce653d" class="outline-2">
<h2 id="org1ce653d"><code>i3exit</code> - Manage lock, suspend, reboot, &#x2026;</h2>
<div class="outline-text-2" id="text-org1ce653d">
<div class="org-src-container">
<pre class="src src-bash">option=$(echo -e "Lock\nExit\nLogout\nSuspend\nHibernate\nReboot\nShutdown" | rofi -i -dmenu)
case "$option" in
"Lock")
~/.local/bin/lockscreen
;;
"Exit")
dm-tool switch-to-greeter
;;
"Logout")
loginctl terminate-session `loginctl session-status | head -n 1 | awk '{print $1}'`
;;
"Suspend")
systemctl suspend &amp;&amp; ~/.local/bin/lockscreen
;;
"Hibernate")
systemctl hibernate &amp;&amp; ~/.local/bin/lockscreen
;;
"Reboot")
systemctl reboot
;;
"Shutdown")
systemctl poweroff
;;
*)
echo "== ! i3exit: missing or invalid argument ! =="
exit 2
esac
exit 0
</pre>
</div>
</div>
</div>
<div id="outline-container-org91bab59" class="outline-2">
<h2 id="org91bab59"><code>askpass-rofi</code> - GUI prompt for passwords</h2>
<div class="outline-text-2" id="text-org91bab59">
<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>
<div class="org-src-container">
<pre class="src src-bash">rofi -dmenu \
-password \
-no-fixed-num-lines \
-p "$(printf "$1" | sed s/://)"
</pre>
</div>
</div>
</div>
<div id="outline-container-org2d85447" class="outline-2">
<h2 id="org2d85447"><code>screenshot</code> - Take Screenshot</h2>
<div class="outline-text-2" id="text-org2d85447">
<div class="org-src-container">
<pre class="src src-bash">status=$(echo -e "All\nGUI\nSelection\nCropped\nCopy\nShadow\nActive" | rofi -i -dmenu -p "Type")
if [ -z "$status" ]; then
exit;
fi
name=$(echo -e "screenshot-$(date +"%m-%d-%y_%H-%M-%S")" | rofi -i -dmenu -p "Filename")
if [ -z "$name" ]; then
exit;
fi
case "$status" in
"All")
maim ~/Pictures/$name.png ;;
"GUI")
flameshot gui -r &gt; ~/Pictures/$name.png ;;
"Selection")
maim -s ~/Pictures/$name.png ;;
"Cropped")
maim -s ~/Pictures/$name.png &amp;&amp; convert -trim ~/Pictures/$name.png ~/Pictures/$name.png;;
"Copy")
maim -s | xclip -selection clipboard -t image/png ;;
"Shadow")
maim -st 9999999 | convert - \( +clone -background black -shadow 80x3+5+5 \) +swap -background none -layers merge +repage ~/Pictures/$name.png ;;
"Active")
maim -i $(xdotool getactivewindow) ~/Pictures/$name.png ;;
esac
</pre>
</div>
</div>
</div>
<div id="outline-container-org8a00ba3" class="outline-2">
<h2 id="org8a00ba3"><code>network-toggle</code> - Toggle Network</h2>
<div class="outline-text-2" id="text-org8a00ba3">
<div class="org-src-container">
<pre class="src src-bash">result=$(nmcli device | sed '1d' | dmenu -l 20);
interface=$(echo $result | awk -F ' ' '{print $1}');
status=$(echo $result | awk -F ' ' '{print $3}');
if [ $status == 'disconnected' ]; then
nmcli device connect $interface
else
nmcli device disconnect $interface
fi
</pre>
</div>
</div>
</div>
<div id="outline-container-orgd568e72" class="outline-2">
<h2 id="orgd568e72"><code>make-gif</code> - Make GIF</h2>
<div class="outline-text-2" id="text-orgd568e72">
<div class="org-src-container">
<pre class="src src-bash">palette="/tmp/palette.png"
filters="fps=15,scale=320:-1:flags=lanczos"
ffmpeg -v warning -i $1 -vf "$filters,palettegen" -y $palette
ffmpeg -v warning -i $1 -i $palette -lavfi "$filters [x]; [x][1:v] paletteuse" -y $2
</pre>
</div>
</div>
</div>
<div id="outline-container-orgd7e49ff" class="outline-2">
<h2 id="orgd7e49ff"><code>yt-audio</code> - Download-Audio from youtube</h2>
<div class="outline-text-2" id="text-orgd7e49ff">
<div class="org-src-container">
<pre class="src src-bash">if [ $TMUX ]; then
tmux split -v -l 5 "cd ~/Downloads/ &amp;&amp; youtube-dl --add-metadata -xic -f bestaudio/best $1" &amp;&amp; tmux select-pane -U
else
cd ~/Downloads/;
setsid nohup youtube-dl --add-metadata -xic -f bestaudio/best $1 &amp;&gt; /dev/null &amp;
fi
</pre>
</div>
</div>
</div>
<div id="outline-container-org89810de" class="outline-2">
<h2 id="org89810de"><code>yt-video</code> - Download-Video from youtube</h2>
<div class="outline-text-2" id="text-org89810de">
<div class="org-src-container">
<pre class="src src-bash">if [ $TMUX ]; then
tmux split -v -l 5 "cd ~/Downloads/ &amp;&amp; youtube-dl --add-metadata -ic $1" &amp;&amp; tmux select-pane -U
else
cd ~/Downloads/;
setsid nohup youtube-dl --add-metadata -ic $1 &amp;&gt; /dev/null &amp;
fi
</pre>
</div>
</div>
</div>
<div id="outline-container-org539efcb" class="outline-2">
<h2 id="org539efcb"><code>setbg</code> - Set Background</h2>
<div class="outline-text-2" id="text-org539efcb">
<div class="org-src-container">
<pre class="src src-bash">bgloc="${XDG_CACHE_HOME:-$HOME/.cache/}/bg"
[ -f "$1" ] &amp;&amp; ln -sf "$(readlink -f "$1")" "$bgloc"
[ -d "$1" ] &amp;&amp; ln -sf "$(find "$(readlink -f "$1")" -iregex '.*.\(jpg\|jpeg\|png\|gif\)' -type f | shuf -n 1)" "$bgloc"
xwallpaper --zoom "$bgloc"
</pre>
</div>
</div>
</div>
<div id="outline-container-org229006d" class="outline-2">
<h2 id="org229006d"><code>insert-unicode</code> - Insert Unicode Icon</h2>
<div class="outline-text-2" id="text-org229006d">
<div class="org-src-container">
<pre class="src src-bash"># Must have xclip installed to even show menu.
xclip -h 2&gt;/dev/null || exit 1
chosen=$(cut -d ';' -f1 ~/.local/data/emojis | rofi -dmenu -i -l 20 | sed "s/ .*//")
[ "$chosen" != "" ] || exit
# If you run this command with an argument, it will automatically insert the character.
if [ -n "$1" ]; then
xdotool key Shift+Insert
else
echo "$chosen" | tr -d '\n' | xsel -ib
dunstify "'$chosen' copied to clipboard." &amp;
fi
</pre>
</div>
</div>
</div>
<div id="outline-container-orgf4064e2" class="outline-2">
<h2 id="orgf4064e2"><code>insert-nerd-fonts</code> - Insert Nerd Font Icon</h2>
<div class="outline-text-2" id="text-orgf4064e2">
<div class="org-src-container">
<pre class="src src-bash"># Must have xsel installed to even show menu.
xsel -h 2&gt;/dev/null || exit 1
chosen=$(cat ~/.local/data/nerd-fonts | rofi -dmenu -i -l 20 | sed "s/ .*//")
[ "$chosen" != "" ] || exit
# If you run this command with an argument, it will automatically insert the character.
if [ -n "$1" ]; then
xdotool key Shift+Insert
else
echo "$chosen" | tr -d '\n' | xsel -ib
dunstify "'$chosen' copied to clipboard." &amp;
fi
</pre>
</div>
</div>
</div>
<div id="outline-container-org2796c9b" class="outline-2">
<h2 id="org2796c9b"><code>linkhandler</code> - Open with Default application</h2>
<div class="outline-text-2" id="text-org2796c9b">
<p>
Inspired from <code>linkhandler</code> <a href="https://github.com/LukeSmithxyz/voidrice/">https://github.com/LukeSmithxyz/voidrice/</a>
This is used in <code>newsboat</code> to handle links
</p>
<div class="org-src-container">
<pre class="src src-bash">[ -z "$1" ] &amp;&amp; { "$BROWSER"; exit; }
case "$1" in
*mkv|*webm|*mp4|*youtube.com/watch*|*youtube.com/playlist*|*youtu.be*|*hooktube.com*|*bitchute.com*)
setsid mpv --input-ipc-server=/tmp/mpvsoc$(date +%s) -quiet "$1" &gt;/dev/null 2&gt;&amp;1 &amp; ;;
*png|*jpg|*jpe|*jpeg|*gif)
curl -sL "$1" &gt; "/tmp/$(echo "$1" | sed "s/.*\///")" &amp;&amp; sxiv -a "/tmp/$(echo "$1" | sed "s/.*\///")" &gt;/dev/null 2&gt;&amp;1 &amp; ;;
*mp3|*flac|*opus|*mp3?source*)
setsid tsp curl -LO "$1" &gt;/dev/null 2&gt;&amp;1 &amp; ;;
*)
if [ -f "$1" ]; then "$TERMINAL" -e "$EDITOR $1"
else setsid $BROWSER "$1" &gt;/dev/null 2&gt;&amp;1 &amp; fi ;;
esac
</pre>
</div>
</div>
</div>
<div id="outline-container-org56e0cc2" class="outline-2">
<h2 id="org56e0cc2"><code>lockscreen</code> - LockScreen</h2>
<div class="outline-text-2" id="text-org56e0cc2">
<p>
First, turn off dunst
</p>
<div class="org-src-container">
<pre class="src src-bash">killall -SIGUSR1 dunst &amp;&amp; echo "off" &gt; /tmp/dunststatus;
</pre>
</div>
<p>
Turn off the music if it is playing.
</p>
<div class="org-src-container">
<pre class="src src-bash">MPC_STATE=$(mpc | sed -n '2p' | cut -d "[" -f2 | cut -d "]" -f1)
if [[ $MPC_STATE == "playing" ]]; then
mpc pause
fi
</pre>
</div>
<p>
Then take a screenshot and process it.
</p>
<div class="org-src-container">
<pre class="src src-bash">temp_file="/tmp/screen.png"
rm -f $temp_file
maim $temp_file
convert $temp_file -scale 10% -scale 1000% $temp_file
</pre>
</div>
<p>
Finally, lock the screen using <code>i3lock</code>.
</p>
<div class="org-src-container">
<pre class="src src-bash">i3lock --no-unlock-indicator --ignore-empty-password --nofork --image=$temp_file &amp;&amp; killall -SIGUSR2 dunst &amp;&amp; echo "on" &gt; /tmp/dunststatus
</pre>
</div>
<div class="org-src-container">
<pre class="src src-bash">revert() {
xset dpms 0 0 0
}
trap revert HUP INT TERM
# turn off screen after 5 seconds
xset +dpms dpms 5 5 5
# Parameters
temp_file="/tmp/screen.png"
icon="$HOME/Pictures/Evil_Rick_Sprite.png"
width=1920
height=1080
blur_factor=6
lock_blur_factor=0
# Take the screen shot, blur the image and add the icon
ffmpeg -f x11grab -video_size "${width}x${height}" -y -i $DISPLAY -i $icon -filter_complex "boxblur=$blur_factor:$blur_factor,overlay=(main_w-overlay_w)/2:(main_h-overlay_h)/2,boxblur=$lock_blur_factor:$lock_blur_factor" -vframes 1 $temp_file
# Alternative
# maim -d 1 $temp_file
# convert -blur 0x8 $temp_file $temp_file
# convert -composite $temp_file $icon -gravity South -geometry -20x1200 $temp_file
# Lock the screen with the image
i3lock --no-unlock-indicator --ignore-empty-password --show-failed-attempts --nofork --image=$temp_file
# Remove the screenshot
rm $temp_file
# Don't turn off screen when back from lock
revert
</pre>
</div>
</div>
</div>
<div id="outline-container-orgbe881e3" class="outline-2">
<h2 id="orgbe881e3"><code>mopidy-restart</code> - Restart Mopidy</h2>
<div class="outline-text-2" id="text-orgbe881e3">
<div class="org-src-container">
<pre class="src src-bash">pids=( $(pgrep -f mopidy) )
for pid in "${pids[@]}"; do
if [[ $pid != $$ ]]; then
kill "$pid"
fi
done
echo "Killed mopidy."
echo "Restarting mopidy..."
mopidy --config ~/.config/mopidy/mopidy.conf &gt;/dev/null 2&gt;&amp;1 &amp;
echo "Done"
</pre>
</div>
</div>
</div>
<div id="outline-container-orgffe5d25" class="outline-2">
<h2 id="orgffe5d25"><code>upload</code> - Upload Script</h2>
<div class="outline-text-2" id="text-orgffe5d25">
<div class="org-src-container">
<pre class="src src-bash">if [ $TMUX ]; then
tmux split -v -l 1 "curl --progress-bar -F\"file=@$1\" https://0x0.st | xsel -ib;" &amp;&amp; tmux select-pane -U
else
curl --progress-bar -F"file=@$1" https://0x0.st | xsel -ib &amp;&amp; \
dunstify 'Upload' 'Successful' || \
dunstify --urgency=critical 'Upload' 'Failed'
fi
</pre>
</div>
</div>
</div>
<div id="outline-container-orgcd16f91" class="outline-2">
<h2 id="orgcd16f91"><code>weather</code> - Display Weather in terminal</h2>
<div class="outline-text-2" id="text-orgcd16f91">
<div class="org-src-container">
<pre class="src src-bash">if [ -n "$*" ]; then
address="wttr.in/"
address+=$*
else
address="wttr.in/"
fi
if type sxiv &gt; /dev/null 2&gt;&amp;1; then
address+=".png"
wget -qO- "$address" &gt; /tmp/weather.png &amp;&amp; \
sxiv -b /tmp/weather.png
elif type feh &gt; /dev/null 2&gt;&amp;1; then
address+=".png"
wget -qO- "$address" | feh -
else
curl "$address"
fi
</pre>
</div>
</div>
</div>
<div id="outline-container-org17ef4d2" class="outline-2">
<h2 id="org17ef4d2"><code>readbib</code> - Open Bibliography File</h2>
<div class="outline-text-2" id="text-org17ef4d2">
<div class="org-src-container">
<pre class="src src-bash">cd ~/Cloud/pdfs/ &amp;&amp; ls | rofi -dmenu -lines 20 | xargs -I {} zathura {}
</pre>
</div>
</div>
</div>
<div id="outline-container-orgda667bb" class="outline-2">
<h2 id="orgda667bb"><code>readnotes</code> - Open Note File</h2>
<div class="outline-text-2" id="text-orgda667bb">
<div class="org-src-container">
<pre class="src src-bash">cd ~/Cloud/thesis/ressources/notes/pdfs/ &amp;&amp; ls *.pdf | rofi -dmenu -lines 20 | xargs -I {} zathura {}
</pre>
</div>
</div>
</div>
<div id="outline-container-orge45135c" class="outline-2">
<h2 id="orge45135c"><code>pdf2bib</code> - Extract bibtex entry from PDF file</h2>
<div class="outline-text-2" id="text-orge45135c">
<div class="org-src-container">
<pre class="src src-bash">pdf2doi () {
pdfinfo "$1" | grep -io "doi:.*" | grep -Poi "10.\d+/[^\s]+" || \
pdftotext "$1" 2&gt;/dev/null - | grep -io "doi:.*" -m 1 | grep -Poi "10.\d+/[^\s]+" || \
pdftotext "$1" 2&gt;/dev/null - | grep -Poi "10.\d+/[^\s]+"
}
doi2bib () {
# curl -LHs "Accept: application/x-bibtex" http://dx.doi.org/$1 -w "\\n"
curl -s "http://api.crossref.org/works/$1/transform/application/x-bibtex" -w "\\n"
}
# If a file is specified, try to extract DOI from the file
if [ -f "$1" ]; then
doi=$(pdf2doi "$1")
fi
if hash rofi 2&gt;/dev/null; then
doi=$(echo "$doi" | rofi -i -dmenu -p "DOI")
else
doi=$(echo "$doi" | dmenu -i -p "DOI")
fi
if [ -n "$1" ]; then
doi2bib $doi | xsel -ib &amp;&amp; \
dunstify 'BibTeX' 'Copied to Clipboard' || \
dunstify --urgency=critical 'BibTeX' 'Failed'
fi
</pre>
</div>
</div>
</div>
<div id="outline-container-org70ec456" class="outline-2">
<h2 id="org70ec456"><code>pdf2png</code> - Convert a PDF to PNG</h2>
<div class="outline-text-2" id="text-org70ec456">
<div class="org-src-container">
<pre class="src src-bash">if [[ -f $1 &amp;&amp; $1 == *.pdf ]]; then
pdftoppm -png $1 &gt; $(echo $1 | cut -f 1 -d '.' | sed 's/$/.png/')
fi
</pre>
</div>
</div>
</div>
<div id="outline-container-org7601ca9" class="outline-2">
<h2 id="org7601ca9"><code>pdf-shrink</code> - Pdf Shrink</h2>
<div class="outline-text-2" id="text-org7601ca9">
<div class="org-src-container">
<pre class="src src-bash">shrink ()
{
gs \
-q -dNOPAUSE -dBATCH -dSAFER \
-sDEVICE=pdfwrite \
-dCompatibilityLevel=1.3 \
-dPDFSETTINGS=/screen \
-dEmbedAllFonts=true \
-dSubsetFonts=true \
-dAutoRotatePages=/None \
-dColorImageDownsampleType=/Bicubic \
-dColorImageResolution=$3 \
-dGrayImageDownsampleType=/Bicubic \
-dGrayImageResolution=$3 \
-dMonoImageDownsampleType=/Subsample \
-dMonoImageResolution=$3 \
-sOutputFile="$2" \
"$1"
}
check_smaller ()
{
# If $1 and $2 are regular files, we can compare file sizes to
# see if we succeeded in shrinking. If not, we copy $1 over $2:
if [ ! -f "$1" -o ! -f "$2" ]; then
return 0;
fi
ISIZE="$(echo $(wc -c "$1") | cut -f1 -d\ )"
OSIZE="$(echo $(wc -c "$2") | cut -f1 -d\ )"
if [ "$ISIZE" -lt "$OSIZE" ]; then
echo "Input smaller than output, doing straight copy" &gt;&amp;2
cp "$1" "$2"
fi
}
usage ()
{
echo "Reduces PDF filesize by lossy recompressing with Ghostscript."
echo "Not guaranteed to succeed, but usually works."
echo " Usage: $1 infile [outfile] [resolution_in_dpi]"
}
IFILE="$1"
# Need an input file:
if [ -z "$IFILE" ]; then
usage "$0"
exit 1
fi
# Output filename defaults to "-" (stdout) unless given:
if [ ! -z "$2" ]; then
OFILE="$2"
else
OFILE="-"
fi
# Output resolution defaults to 72 unless given:
if [ ! -z "$3" ]; then
res="$3"
else
res="90"
fi
shrink "$IFILE" "$OFILE" "$res" || exit $?
check_smaller "$IFILE" "$OFILE"
</pre>
</div>
</div>
</div>
<div id="outline-container-org4041717" class="outline-2">
<h2 id="org4041717"><code>pdf-delete-annotations</code> - Delete Annotations from PDFs</h2>
<div class="outline-text-2" id="text-org4041717">
<p>
From: <a href="https://gist.github.com/stefanschmidt/5248592">https://gist.github.com/stefanschmidt/5248592</a>
</p>
<div class="org-src-container">
<pre class="src src-bash">pdftk $1 output /tmp/uncompressed.pdf uncompress
LANG=C sed -n '/^\/Annots/!p' /tmp/uncompressed.pdf &gt; /tmp/stripped.pdf
pdftk /tmp/stripped.pdf output $1 compress
</pre>
</div>
</div>
</div>
<div id="outline-container-orge18f381" class="outline-2">
<h2 id="orge18f381"><code>pdf-delete-first-page</code> - Delete first page of PDF</h2>
<div class="outline-text-2" id="text-orge18f381">
<p>
The requirement is to have <code>pdftk</code> or <code>stapler</code> installed.
</p>
<div class="org-src-container">
<pre class="src src-bash">if [[ -f $1 &amp;&amp; $1 == *.pdf ]]; then
# Argument if a file
if type stapler &gt; /dev/null 2&gt;&amp;1; then
stapler del "$1" 1 /tmp/pdftk_out.pdf &amp;&amp; mv /tmp/pdftk_out.pdf "$1"
elif type pdftk &gt; /dev/null 2&gt;&amp;1; then
pdftk "$1" cat 2-end output /tmp/pdftk_out.pdf &amp;&amp; mv /tmp/pdftk_out.pdf "$1"
else
echo "Neither pdftk nor stapler are installed"
fi
fi
</pre>
</div>
</div>
</div>
</div>
<div id="postamble" class="status">
<p class="author">Author: Dehaeze Thomas</p>
<p class="date">Created: 2020-05-26 mar. 08:39</p>
</div>
</body>
</html>