Bash Scripts and Oneliners

Currently reading:
Bash Scripts and Oneliners

b4rkod

New member
comfy friend
Joined
Apr 21, 2024
Messages
4
Reaction score
3
comfy coins
šŸ’ 6,859
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"
 
/pub/ ~ public channel
Help Users
  • X (Guest) Xis350 from other device:
    yeah that's still me I'm just too lazy to log in
    Quote Link
  • Xis350 @ Xis350:
    Xis350 said:
    so yeah I'd be really glad to have some feedback
    Quote Link
  • B Chat Bot:
    Guest Blu has joined the room.
  • B (Guest) Blu:
    Hello?
    Quote Link
  • B (Guest) Blu:
    I think I'm lost. Where am I?
    Quote Link
  • B (Guest) Blu:
    Actually, I have seen this site before, don't know why.
    Quote Link
  • Xis350 @ Xis350:
    Huh you might have been
    Quote Link
  • Luna Chat Bot:
    Luna Luna has joined the room.
  • B Chat Bot:
    Guest Blu has joined the room.
  • B (Guest) Blu:
    I'm back
    Quote Link
  • Xeraser @ Xeraser:
    oh thank God it's FINALLY july
    Quote Link
  • Kevin Logan @ Kevin Logan:
    Why finally?
    Quote Link
  • I Chat Bot:
    Guest its a lot has joined the room.
  • watts5002 Chat Bot:
    watts5002 watts5002 has joined the room.
  • KENSUKE SASAKI @ KENSUKE SASAKI:
    any other SP bandits in the house (3.12 inches bone pressed)
    Quote Link
  • Ogyn @ Ogyn:
    What's SP
    Quote Link
  • G Chat Bot:
    Guest goody has joined the room.
  • G (Guest) goody:
    GFX VFX sound effects - MEGAPACK wheeeeeeeeen
    Quote Link
  • G (Guest) goody:
    GFX VFX sound effects - MEGAPACK v2 imeant
    Quote Link
  • G (Guest) goody:
    pls ninturez0 ninturez0 any updates ???
    Quote Link
  • watts5002 @ watts5002:
    osrs launches its new engine into beta today at 11:30! :)
    Quote Link
  • L Chat Bot:
    Guest lilboy has joined the room.
  • L (Guest) lilboy:
    hiii
    Quote Link
  • Ogyn @ Ogyn:
    hi
    Quote Link
  • fistedwiz @ fistedwiz:
    Hello
    Quote Link
      fistedwiz @ fistedwiz: Hello
      Back
      Top