[a / b / c / d / e / f / g / gif / h / hr / k / m / o / p / r / s / t / u / v / vg / vm / vmg / vr / vrpg / vst / w / wg] [i / ic] [r9k / s4s / vip / qa] [cm / hm / lgbt / y] [3 / aco / adv / an / bant / biz / cgl / ck / co / diy / fa / fit / gd / hc / his / int / jp / lit / mlp / mu / n / news / out / po / pol / pw / qst / sci / soc / sp / tg / toy / trv / tv / vp / vt / wsg / wsr / x / xs] [Settings] [Search] [Mobile] [Home]
Board
Settings Mobile Home
/g/ - Technology


Thread archived.
You cannot reply anymore.


[Advertise on 4chan]


File: bash.png (43 KB, 3000x2000)
43 KB
43 KB PNG
Post dem bash scripts and commands.
Here's a simple script that will make your 4:3 anime files playable on a Nintendo Wii, they look really nice on a CRT:
#!/bin/bash

mkdir -p hardcoded
mkdir -p converted

for file in *.mkv; do

filename=$(basename "$file" .mkv)

ffmpeg -i "$file" -vf subtitles="'$file':si=0" -c:a copy "hardcoded/${filename}.mkv"

ffmpeg -i "hardcoded/${filename}.mkv" -aspect 4:3 -vf scale=640:480:flags=neighbor -c:v libxvid -b:v 2500k -r 30 "converted/${filename}.mp4"

done

rm -R "hardcoded"

Suggestions for improvement welcome.
>>
got this from that Pajeet youtuber, added some options i find useful
its quite practical

#!/bin/sh

OPT=" -hide_banner -loglevel error -stats"
for ext; do true; done
if ([ -z "$1" ] || [ -z "$2" ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]); then
printf "Usage: cvrt [infiles...] [format out]\n"; exit 0
fi
# Exception options for specific formats
case "$ext" in
# Default presets
*flac) OPT=$OPT:" -vn" ;;
*mov) OPT=$OPT:" -c:v mpeg4 -q:v 0 -pix_fmt yuv420p -c:a pcm_s16le" ;;
*4) OPT=$OPT:" -c:v libx264 -crf 21 -c:a libopus -b:a 320k" ; ext='mp4' ;;
*3) OPT=$OPT:" -b:a 320k" ; ext='mp3' ;;
*png) OPT=$OPT:" -s 512x512" ;;
# Custom presets
*w) OPT=$OPT:" -c:a libvorbis -c:v libvpx -crf 6" ; ext='webm' ;;
*reduce) OPT=$OPT;" -c:a libvorbis -c:v libvpx -ar 8000 -c:a libvorbis -b:a 16k"; ext='webm' ;;
*gif) OPT=$OPT;" -vf '"fps=10,scale=480:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse"' -loop 0" ; ext='gif' ;; # in comment: https://superuser.com/a/730389
*oo) OPT=$OPT;" -vf "overlay=0:0""
esac

if (echo $ext | grep "\." && [ -z $3 ]); then
ffmpeg -i "$1" $OPT "$ext"
exit 0; fi

for i in "$@"; do
[ "$i" != "$ext" ] && ffmpeg -i "$i" $OPT "${i%.*}.$ext"
done; exit 0
>>
anons I want to be git gud at bash ;_;

sometimes I discover stuff like alias command and feel like a god but other times i try to do simple stuff like search a log file by time-stamps and realize how retarded i am. How to become bash command gigachad?
>>
when goyim musk forced twatter accounts to play videos I used this
you first have to copy a video url from YT twatter or something else (the third party frontends like nitter and pipe work all the same) then exec the script, requires dmenu

#!/bin/sh

# Get user selection for platforms via dmenu
SELECTED_DOMAIN=$(echo -e "\nyt:youtube.com\ntw:twitter.com\np:PLAY" | dmenu -i -l 4 | sed "s/.*://")
# exit if none chosen
[ -z "$SELECTED_DOMAIN" ] && exit

# get url from clipboard
url=$(xclip -o -sel c)

# if a platform was chosen (ie, no the 'PLAY' value), replace the domain name in the url
[[ ! "$SELECTED_DOMAIN" = 'PLAY' ]] && url=$(echo "$url" | sed -e "s/\([^/]*\/\/\([^@]*@\)\?\)\([^:/]*\)\(.*\)/\1$SELECTED_DOMAIN\4/")

# play the url
[[ "$url" == *"twitter"* || "$url" == *"x.com"* ]] && mpv --ytdl-raw-options=username=<throw account username>,password=<throw account password> --force-window=immediate "$url" || mpv --force-window=immediate "$url"
>>
alright i'll say it
bash is a stupid language with a deranged syntax
>>
>>100159387
it's all korn shell's fault
those double brackets make my eyes bleed
>>
>>100159387
lol wait til you have to write scripts on shitty old embedded linux systems with only bizarre non-conforming ash/sh available
>>
>>100159450
this
the other day I learned the hard way that some ancient shells reset positional parameters list when you call a function from within a function
>>
>>100159286
Check this out, it's really good for a beginner and is what I used first
https://archive.flossmanuals.net/command-line/
>>
>>100159286
If googling doesn't give you a solution, try reading the man. Mans are written by autists so it will sometimes be a waste of time but it's important to learn how to navigate them and find the info you're looking for.
If you find nothing try asking stackoverflow or one of the appropriate subforums
If that doesn't work try asking an AI chatbot but be careful about executing any comands they give you.

Be sure to keep a file with the commands you found the most useful, preferably with some commentary on your part and links to where you found your answers.
The more you grow your notes the less you will rely on search engines and forums, here's an example https://lostpon.gitlab.io/checkmate/memento.html

To organize your aliases try to find the commands you use the most, but the history command is chronological and it is numbered like this
10 calc 8*8000000/10
11 update
12 convert IMG_20221222_141205_523.jpg -crop 3840x2160+830+0 doc.jpg
13 cd Pictures/art/designs

Googling "bash history cut" gives
cut -c 8-
as a first result, so now we can sort the commands and keep the most used
(google "bash uniq occurrences")
history | cut -c 8- | sort | uniq -c | sort -nr | head -n 10


Now you have the top 10 most used commands according to your bash history, this is just an example
Write down some notes about the history, sort, cut, uniq and head commands and proceed to think of some convenient aliases for the top 10 lines. This is how I got myself stuck inside the terminal and now I can't get out
>>
>>100159354
>requires dmenu
Why?
>>
>>100160012
Keep in mind that you will reach a point where it will take more time trying to save yourself time than it would be to just do what you wanted.
>>
>>100160012
What kind of weirdo says "man" instead of "manual"? Or at least "manpage."
>>
>>100160299
to select which platform you want to read a video from

>>100160424
oh what so i need to respect the manual's pronouns as well now
>>
>>100160424
>Literally called the man command

You are a fucking faggot. Go back to india
>>
>>100160458
Now I see why.
>tell me you are a retard without actually telling me you are retarded.
>>
4code () 
{
[ $# -ge 1 ] && ls --color=auto -L --zero "$@" | xargs -0n 1 sed -z 's|^|
|;s|\n$|
\n|' || sed -z 's|^||;s|$|\n|'
}
fzcd ()
{
case "$#" in
0)
onlyInDir=. searchDir=""
;;
1 | 2)
onlyInDir="$1" searchDir="$2"
;;
*)
echo "Too many or not enough arguments." 1>&2;
return 1
;;
esac;
local result="$(find -L -- "$onlyInDir" -type d -ipath "*$searchDir*" | fzf)";
[ -n "$result" ] && cd "$result" || return 1
}
fzpd ()
{
local dirNum="$(dirs -v | grep -v '^ 0' | fzf | cut -d\ -f2)";
[ "$dirNum" ] || return 1;
pushd +${dirNum}
}
fzppd ()
{
local dirNum="$(dirs -v | grep -v '^ 0' | fzf | cut -d\ -f2)";
[ "$dirNum" ] || return 1;
popd +${dirNum}
}
fzrm ()
{
local dir="${1%/}";
ls --color=auto -N --group-directories-first -t "${dir:-.}"/*.* | fzf --multi --print0 | xargs -r0 rm -v --
}
hawk ()
{
awk '{a[$1]++}END{for(i in a){print a[i] " " i}}' "$HISTFILE" | sort -nr | head -n ${1:-10}
}
mkcd ()
{
mkdir -p "$1" && cd "$_"
}
playLatest ()
{
ls --color=auto -N --group-directories-first -t --zero ./*.* | xargs -r0 mpv --speed="${1:-1.25}"
}
qcd ()
{
local depth="${2:-1}";
local search="$(find -L -maxdepth "$depth" -type d -ipath "*$1*")";
local length="$(echo -e "$search" | wc -l)";
[ "$search" ] && if [ "$length" = "1" ]; then
cd "$search" && return 0;
else
local tryAgain="$(echo "$search" | fzf --prompt="Which one? > ")";
[ "$tryAgain" ] && cd "$tryAgain" && return 0 || return 1;
fi || echo "qcd: $1: no such directory" 1>&2;
return 1
}
.. ()
{
local d="";
local limit="${1:-1}";
for ((i=1; i<=limit; i++))
do
d="../$d";
done;
if ! cd "$d"; then
echo "Couldn't go back $limit dirs." 1>&2;
return 1;
fi
}
>>
>>100162015
let's see if I formatted 4code right this time
4code is a function
4code ()
{
[ $# -ge 1 ] && ls --color=auto -L --zero "$@" | xargs -0n 1 sed -z 's|^|\[code\]|;s|\n$|\[/code\]\n|' || sed -z 's|^|\[code\]|;s|$|\[/code\]\n|'
}

just remove those backslashes if they show up
>>
>>100162015
what does this do
>>
>>100163796
they're just a handful of bash functions I use
>>
>>100158613
funny I wrote a powershell script that does this as well recently



[Advertise on 4chan]

Delete Post: [File Only] Style:
[Disable Mobile View / Use Desktop Site]

[Enable Mobile View / Use Mobile Site]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.