[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

Post your bash scripts, oneliners and aliases. zsh hipsters don't

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 33
Thread images: 3

File: 1473051301840.jpg (15KB, 374x262px) Image search: [Google]
1473051301840.jpg
15KB, 374x262px
Post your bash scripts, oneliners and aliases.
zsh hipsters don't need to apply.
>>
chsh -s /usr/bin/fish
>>
>using the superior shell is being a hipster
>>
>>58042709
this is to grab torrent files with transmision daemon without needing the gtk version, just put this on a file and make an open with
#!/bin/sh
/usr/bin/transmission-remote --add "$1"


create torrents
#!/bin/sh
/usr/bin/transmission-create -o "$1" -t "udp://tracker.openbittorrent.com:80" -t "udp://open.demonii.com:1337" "$2"


QEMU script to install new distros
#!/bin/bash
# Author: svchost
# Date: 08.27.2016
# Purpose: QEMU loading
# License: GPLv3

qemu-system-x86_64 -m 2G -hda $1 -cdrom $2 -boot d


update and clean the system
#!/bin/bash
# Author: svchost
# Date: 05/08/2016
# Purpose: Clean and update Devuan
# License: GPLv3

sudo apt-get autoclean; sudo apt-get clean; sudo apt-get autoremove; sudo apt-get update; sudo apt-get upgrade; sudo apt-get dist-upgrade


bind it to the super key, use ratpoison, and youll have a quick and easy window switch
#!/bin/bash
# Author: svchost
# Date: 05.08.2016
# Purpose: dmenu window switch
# License: GPLv3
ratpoison -c "select `ratpoison -c "windows %t" | dmenu -nf gray -nb black -sf black -sb gray -b -l 20`"
>>
>>58042709
>>58042979
>zsh hipsters don't need to apply
Could someone explain me this? What's wrong with zsh? It feels a lot better that bash to me. I tried to switch back to bash some days ago and I noticed how tons of useful features and arguments completions are missing or needs to be enabled manually.
>>
>>58043721
>licensing the list of arguments you pass to a program
JUST
>>
#!/bin/sh -e

if [ $# -eq 6 ]
then
ffmpeg -y -ss $2 -i "$1" -vf scale=-2:$4 -an -sn -c:v libvpx -threads 4 -quality best -b:v $5k -pass 1 -f webm -t $3 /dev/null
ffmpeg -ss $2 -i "$1" -vf scale=-2:$4 -an -sn -c:v libvpx -threads 4 -quality best -b:v $5k -pass 2 -t $3 "$6-$4p-$5k.webm"
else
echo "usage: $(basename "$0") FILE START LENGTH RESOLUTION BITRATE NAME" >&2
false
fi


Yes I know, it's not a bash script.
>>
>>58042709
So say I have a long command I always type out to open a program, something like:

[TerdFerguson@Nebuchadnezzar ~]$ bash Builds/somefile/bin/someprogram.sh

I want to be able to type in a short word that automatically does that. I think alias is what I want to do but how do I go about it? Tried some stuff already in .bashrc file but it doesn't want to work. For extra info, I'm using arch with i3.
>>
>>58043779
I think it's just like most stuff on here, bash is all he's ever used used, so he dislikes and belittles the alternatives. It's just how things work in here.
>>
>>58043901
What's the significance of the $ in "-ss $2" and "-vf scale=-2:$4" and "-b:v $5k"

I've used ffmpeg to create webms and grab frames into a file, but I'm not at all proficient with automation/scripts in bash, or really any terminal for that matter.
>>
>>58043943
That tends to be how things are everywhere. If some person uses ____ product from ____ manufacturer, they will find ways to justify their choice even if they basically choose it at random to begin with. Kind of like how idiots obsess over Ford vs Dodge based on their parents owning a Ford or based on them buying one or the other for their first vehicle. People like to identify themselves with something, and then use that to argue with others who are "different".
>>
>>58043956
Read the usage line. Everything is explained.
>>
>>58043986
Well that's true, though I think it's more pronounced here since the overall tone is often more confrontational (on internet in general and on 4chan in particular).
>>
>>58043901
What is that?

>>58043913
write the script in a file with the #!/bin/bash in the first line, make it executable, put it in your bin directory
>>
>>58044071
>What is that?
My script to compress webm for 4chan. I could use for anything, but I compress webm only for 4chan.
>>
>>58043817
makes me feel like I am an actual programmer ;^)

two little scripts I put in my .xbindkeys file and bind it to print and scroll lock keys respectively:

take screenshot
import -window root png:$HOME/xwz_$(date "+%Y-%m-%d-%H:%M:%S").png


record desktop
killall -INT avconv 2>/dev/null || avconv -f x11grab -r 25 -s 1280x720 -i :0.0 $HOME/output.webm &


recording the desktop is shitty though, haven't fixed the video quality
>>
#!/bin/sh

tmp=`mktemp`
list_explicit=`mktemp`
pacman -Qe > $list_explicit
list_groups=`mktemp`
pacman -Qg base base-devel | cut -d " " -f2 > $list_groups

while read line
do
grep -vw $line $list_explicit > $tmp
mv $tmp $list_explicit
done < $list_groups

less $list_explicit
rm $list_explicit $list_groups
>>
File: 1459835949150.png (116KB, 250x250px) Image search: [Google]
1459835949150.png
116KB, 250x250px
compress/extract multiple subdirectories
#!/bin/bash

case $1 in
-h | "" )
echo "Usage: bulktar.sh <option>"
echo " -c: compress subdirectories into separate .tgz files"
echo " -x: extract .tgz files"
exit
;;
-c )
for i in */ ; do
echo "Compressing '$i' ..."
tar -pzcvf "${i%/}.tar.gz" "$i"
done
;;
-x )
for i in *.tar.gz ; do
echo "Extracting '$i' ..."
tar -zxvf "$i"
done
;;
esac


gif to webm
#!/bin/bash

for i in *.gif ; do
ffmpeg -i "$i" -pix_fmt yuv320p -c:v libvpx -crf 12 -b:v 500K "$(basename "${i/.gif}").webm" && rm $i
done


fix permissions (644 for files/755 for folders)
#!/bin/bash

read -r -p "You sure? $1 [y/N] " response

if [[ $response =~ ^([yY])$ ]]
then
find $1 \
\( -type f -exec chmod 644 {} \; \) , \
\( -type d -exec chmod 755 {} \; \)
else
echo "Aborted..."
exit 0
fi
>>
I use mksh.
>>
>>58042709
A few aliases that help me save keystrokes:

alias up="cd ../"
alias upp="cd ../../"
alias uppp="cd ../../../"
alias upppp = "cd ../../../../"

alias pls="sudo"
>>
>>58045206
>alias pls="sudo"
I love you
>>
>>58045158
>fix permissions
You should do it like that.
chmod -R a-st,go=u-w "$1"

is probably better
>>
learning brash expansion rules and learning the order of expansions will open up the world. bash4 or zsh especially have so many niceties these days it's great
>>
>>58043721
- quote your variables
- use && instead of ; since it doesn't make sense to run the other programs when the previous failed
>>
>>58043901
nice
>>
>>58044315
>
killall -INT avconv 2>/dev/null || 

That's genious. Saves me lots of enable/disable hotkeys. Thanks for the idea.
>>
>>58044740
quote variables, use $() instead of ``
>>58045158
nice
>>
>>58045281

Is it possible to use "chmod -R" to force all subdirectories to always have the x bit set whenever the r bit is set -- without adding any x bits to regular files?

I've always had to use "find" for that because I have different rules I want to apply to directories versus regular files, regarding the x bit.
>>
>>58046239
I understand your problem. But except if you did a mistake all the directories must have the x bit set. So you don't really need a script for that.
>>
>>58046058
>use $() instead of ``
Why? `` is more legible for me.
>>
>>58046501
It's old, deprecated syntax which is sadly still around. It's also better when you want to nest things. Check the bash hackers wiki for more info.
>>
>>58045995
>quote your variables
I guess you mean "%t"? k
>use && instead of ; since it doesn't make sense to run the other programs when the previous failed
roger that

>>58046028
thanks, glad to know is useful
>>
>>58043913
Post the alias?
Also bashrc gets sourced only on startup
Or you need to reload it with source ~/.bashrc
Thread posts: 33
Thread images: 3


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
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.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.