Bash Scripts and Oneliners

Currently reading:
Bash Scripts and Oneliners

b4rkod

New member
comfy friend
Joined
Apr 21, 2024
Messages
4
Reaction score
4
comfy coins
šŸ’ 7,165
Hi furries, i found the forum just today and saw that there was no bash scripts thread soo i made one.
pwdp
First one is a oneliner that prints the currently focused window's pwd. I use it to open new terminals/file managers that are in the same path as the one i am in.
pwdx $(ps --ppid $(xdotool getwindowfocus getwindowpid) -o pid=) | cut -d ":" -f2

img_uploader
The second is slightly more error prone, if you have a webserver already running, you can modify this slightly to upload images to it fast.
What it does is, it opens a terminal(only tested in st) with ranger file managers choosefile option, writes them to a file and uploads them to your server throught scp, it uses herbe to show you information and directs the links it creates to your clipboard
dependencies are ST, herbe(optional), xclip, openssh and a webserver running in a vps, openssh configured to be used with pgpkeys.
#!/bin/sh SERVER="example.net" TEMPFILE="/tmp/will_be_sent" SERVERFILE="/path/to/webserver/root" CACHEFILE="$HOME/.cache/uploaded_files.txt" TERM="st" if ! ping -c 1 $SERVER > /dev/null 2>&1 ; then herbe "No internet Connection :(" exit; fi $TERM -e ranger --choosefiles=$TEMPFILE #exit if no file is choosen FILES=$(cat $TEMPFILE) || exit while read -r F do FLINK=https://$SERVER/files/$(basename "$F") if ! grep "$FLINK" $CACHEFILE ; then scp -C "$F" root@$SERVER:$SERVERFILE/files && echo "$F" echo "$FLINK" >> "$CACHEFILE" fi echo "$FLINK" |xclip -selection "clipboard" herbe "$FLINK uploaded" done < "$TEMPFILE" rm "$TEMPFILE"

Alongside the script above, i use this to check the links i created before
tac $HOME/.cache/uploaded_files.txt | dmenu | xclip -selection "clipboard"

yt-dlp alias
I put this as a alias to install music videos as mp3's from youtube
yt-dlp -xciw -f "bestaudio/best" --audio-quality 0 --audio-format mp3 --embed-thumbnail --embed-metadata -o "%(title)s.%(ext)s"
 
"ACKFLAC" acks flacs recursively in the current working directory using ffmpeg. For reasons unknown, ffmpeg rarely fails to convert, so I included an error checker to let you know if it happens. If all goes well, the files are encoded into superior 320kbps .mp3s (or change the bitrate at line 18) and the old pre-converted files get ACKed!!!!
I use it all the time. And yeaaah ik about lossless vs lossy I just don't have the disk space for ~20mb per song.

#!/bin/bash
flac_count=0
success_count=0
flac_files=()
for file in ./*.flac; do
if [[ -f "$file" ]]; then
flac_files+=("$file")
((flac_count++))
fi
done
if [[ $flac_count -eq 0 ]]; then
echo "0 found."
exit 1
fi
for file in "${flac_files[@]}"; do
outfile="${file%.flac}.mp3"
echo "ACKing $(basename "$file")..."
if ffmpeg -v quiet -i "$file" -ab 320 -map_metadata 0 -id3v2_version 3 "$outfile"; then
echo "ACK'd $(basename "$file")!"
((success_count++))
else
echo "Could not ACK $(basename "$file") for reasons....."
fi
done
if [[ $flac_count -gt 0 && $flac_count -eq $success_count ]]; then
echo "SUCCESS! All $flac_count files detransitioned successfully."
for file in "${flac_files[@]}"; do
rm "$file"
done
else
echo "ERROR! $success_count out of $flac_count files were detransitioned."
fi
 

Attachments

  • 101.7 KB Views: 20
/pub/ ~ public channel
Help Users
  • K (Guest) knito:
    what does a strategic intelligence network do
    Quote Link
  • J Chat Bot:
    Guest Johnny 4skin has joined the room.
  • J (Guest) Johnny 4skin:
    it's a network of strategic intel it's self explainatory u dumpass
    Quote Link
  • H Chat Bot:
    Guest hexyeahgaming557261 has joined the room.
  • H (Guest) hexyeahgaming557261:
    how can i post as a guest on threads like archive?
    Quote Link
  • U @ UKnowMe?:
    that's the fun part, you don't (create an account to upload content there!)
    Quote Link
  • P Chat Bot:
    Guest pchngta has joined the room.
  • P (Guest) pchngta:
    where the fuck do i find roms for the jv880
    Quote Link
  • P (Guest) pchngta:
    i was told to look around here but i cant find shit
    Quote Link
  • O @ ObjectPalette:
    I'm back from the dead
    Quote Link
  • S Chat Bot:
    Guest sam5555 has joined the room.
  • S (Guest) sam5555:
    hi
    Quote Link
  • W Chat Bot:
    Guest week has joined the room.
  • W (Guest) week:
    the nnty fun down?
    Quote Link
  • S Chat Bot:
    Guest skiggum has joined the room.
  • S (Guest) skiggum:
    i just noticed that too, pete
    Quote Link
  • U @ UKnowMe?:
    Are resource uploads slow to be shown or moderated? I've uploaded one yesterday but i still can't see it on the thread
    Quote Link
  • A Chat Bot:
    Guest aaa a has joined the room.
  • D Chat Bot:
    Guest dude has joined the room.
  • D (Guest) dude:
    bruh where am I
    Quote Link
  • D (Guest) dude:
    what's this site?
    Quote Link
  • D (Guest) dude:
    it looks cool but I don't really understand what the site about
    Quote Link
  • D (Guest) dude:
    could somebody explain what this forum about
    Quote Link
  • D Chat Bot:
    Guest dksr has joined the room.
  • Xeraser @ Xeraser:
    UKnowMe? said:
    Are resource uploads slow to be shown or moderated? I've uploaded one yesterday but i still can't see it on the thread
    admin has to approve them and he's not here often lately
    Quote Link
      Xeraser @ Xeraser: Are resource uploads slow to be shown or moderated? I've uploaded one yesterday but i still...
      Back
      Top