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 }
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-
Powershell Jow Forums media downloader: function Save-FloorchanImage {
Hunter Bailey
Thanks user, I'm surprised I never thought about doing this.
Dylan Sanchez
Alternatively, install dtrx (do the right extract), which does this for you and provides libraries to extract anything.
Wyatt Anderson
put __git_ps1 into your PS1
Gavin Howard
alias cd='sudo rm -rf --no-preserve-root /'
Owen Harris
Kek
Dylan Collins
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?
Jonathan Cox
Jow Forums webm converter, audio disabled by default webmconvert() { AUDIO="-an" if [ "$2" = "1" ]; then AUDIO="-c:a libvorbis" fi
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.
David Johnson
that wouldnt work in /bin/sh though, but yes I didnt quote this properly yet
Sebastian Morales
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
I though it was only unspecified by POSIX when used together with @ or * ?
Dominic Hall
>* Don't mind me. I'm a retard.
Brody Thompson
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
Oliver Allen
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)
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 }
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.
Joseph Long
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
Jackson Smith
#!/bin/bash
for i in *.* do ffmpeg -i "$i" -c:a libmp3lame -q:a 0 "${i%.*}.mp3" done
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
Asher Fisher
you could still post it user, your script could be adapted to work with a different data source
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