Handy scripts you'd like to share

4 posts were merged into an existing topic: Off Topic Chit Chat - (Silliness factor 5)

Hello there!
Ainโ€™t quite sure is it belongs to this topic, pls correct me if not.

If you are using Sway and struggle to make one wallpaper across two similar monitors (same resolution) without splitting picture then the next hack is for you:

  1. You need to install swaybg-Multi-monitor from Github;
  2. Make modification in the Variety script file ~/.config/variety/scripts/set_wallpaper. In the section which is starting from line 232. please find a lines with command *swaybg -i โ€œ$WPโ€ -m fill * and change option โ€˜fillโ€™ to option โ€˜multi-monitorโ€™, like in example below.
...
PID=`pidof swaybg`
if [[ -n $PID ]]; then
    # If swaybg is available, use it as prevents system freeze.
    # See https://github.com/swaywm/sway/issues/5606
    if command -v "swaybg" >/dev/null 2>&1; then
        # Grey background flicker is prevented by killing old swaybg process after new one.
        # See https://github.com/swaywm/swaybg/issues/17#issuecomment-851680720
        #
        # in the line below - option 'fill' change to 'multi-monitor'
        swaybg -i "$WP" -m multi-monitor &
        if [ ! -z "$PID" ]; then
            sleep 1
            kill $PID 2>/dev/null
        fi
    else
        #
        # in the line below - option 'fill' change to 'multi-monitor'
        swaymsg output "*" bg "$WP" multi-monitor 2> /dev/null
    fi
fi
...

Now in your variety app settings in section Wallpaper you could use Smart mode and your wallpapers could easy span across two displays without additional mods.

BUT once again thatโ€™s all possible if you have - Two monitors with the same resolution horizontally placed.

3 Likes

I have been using fzf for a very short while now. The very first issue I had with this was it not opening its results in an editor. Itโ€™s searches are no doubt great but if it outputs just the file path for me thatโ€™s not very useful now is it.

#!/bin/bash

IFS=$'\n' read -d '\n' -ra fzf_command <<< "$(fzf --height 60% -m -q "${1}" --ansi --preview="bat --style=numbers --color=always {}")"
if [ ${#fzf_command[@]} -ne 0 ]; then
        lvim "${fzf_command[@]}"
fi

So this is what I came up with. This deals with the issue which I encountered where if fzf outputs a file name that has space in itโ€™s name lvim will open it as two different files. The -m option allows me to select multiple files to open at once with tab and -q allows me to run the script with arguments for what I wanna search (which I rarely doโ€ฆ). The preview is pretty self explanatory. :smile:

Got an alias to it and everything.

alias fzfm "/path/to/fzfm.sh"

All in all I think I am quite fond of this method of searching my directory right now. I heard this can reverse lookup my shell history tooโ€ฆ Maybe I will lookup that someday as well. For now this much brain storming is enough. :slightly_smiling_face:

5 Likes

Fine, it works with micro too :smiley:

2 Likes

I could not resist code-golfing it

fzf --height 60% -m -q "${1}" --ansi --preview="bat --style=numbers --color=always {}" |xargs -rd$'\n' $EDITOR

or with zero-delimited strings to allow even newlines and other crap in the filenames

fzf --height 60% -m -q "${1}" --ansi --preview="bat --style=numbers --color=always {}" --print0 |xargs -r0 $EDITOR

not that I would advise using such filenames in the first place

3 Likes

Thatโ€™s a good one. :smile:

2 Likes

Made a fairly handy bulk file/folder renamer:

#!/bin/bash

# Function to add text to filenames
add_text() {
    local dir=$1
    local text=$2
    local position=$3

    cd "$dir" || exit 1

    for entry in *; do
        if [ -d "$entry" ]; then
            mv "$entry" "$text$entry"
        elif [ -f "$entry" ]; then
            if [ "$position" == "beginning" ]; then
                mv "$entry" "$text$entry"
            elif [ "$position" == "end" ]; then
                extension="${entry##*.}"
                filename="${entry%.*}"
                mv "$entry" "$filename$text.$extension"
            fi
        fi
    done

    cd - > /dev/null || exit 1
}

# Function to replace text in filenames
replace_text() {
    local dir=$1
    local old_text=$2
    local new_text=$3

    cd "$dir" || exit 1

    for entry in *; do
        if [ -d "$entry" ]; then
            new_name=$(echo "$entry" | sed "s/$old_text/$new_text/gI")
            mv "$entry" "$new_name"
        elif [ -f "$entry" ]; then
            new_name=$(echo "$entry" | sed "s/$old_text/$new_text/gI")
            mv "$entry" "$new_name"
        fi
    done

    cd - > /dev/null || exit 1
}

# Main script
echo "Bulk renaming script"

# Choose directory through file-picker
directory=$(zenity --file-selection --directory --title="Select Directory")
if [ $? -ne 0 ]; then
    echo "No directory selected. Exiting..."
    exit 1
fi

# Change to the selected directory
cd "$directory" || exit 1

echo "1. Add text to filenames"
echo "2. Replace text in filenames"
read -rp "Choose an option (1/2): " option

case $option in
    1)
        read -rp "Enter the text to add: " text
        read -rp "Should it be appended to the beginning or end? (beginning/end): " position
        echo "Adding \"$text\" to filenames and folder names..."
        add_text "$(pwd)" "$text" "$position"
        ;;
    2)
        read -rp "Enter the text to replace: " old_text
        read -rp "Enter the new text: " new_text
        echo "Replacing \"$old_text\" with \"$new_text\" in filenames and folder names..."
        replace_text "$(pwd)" "$old_text" "$new_text"
        ;;
    *)
        echo "Invalid option, exiting..."
        exit 1
        ;;
esac

echo "Done"

Full explanation of what and why, as well as features and limitations here

1 Like

Sometimes I drop something in the darkness of my room, and Iโ€™m too lazy to switch on the lights.

For that reason I made this:

#!/bin/bash

# Let there be light!
shopt -s checkwinsize
(:)
printf -v BUFFER '%*s' $((COLUMNS*LINES)) ' '
printf '\033[48;2;255;255;255m%s\n\033[0m' "$BUFFER"

I just run light in my terminal. On my big screen, itโ€™s quite enough to illuminate the whole room. When Iโ€™m done, a simple clear brings back the darkness.

pepe nuclear

8 Likes

@Kresimir, nice to see youโ€™re still hanging around the forum olโ€™buddy.

I fear my eyes couldnโ€™t take the blare created by your handy script. Everything is in dark mode on my computer to lessen the eye strain.

Cheers bud. :beers:

5 Likes

My eyes!
honka_animated-128px-34

1 Like

If you canโ€™t be bothered to look up the systemd service syntax all the time, check systemd-run. It automatically generates services and even their timers which are temporarily active. Then you can just systemctl --user cat <servicename>.service and the same for the timer and you get a working service with almost zero effort.
Donโ€™t forget to stop (and disable?) the service afterwards :wink:

I love this tool. Makes services 200% easier.

2 Likes

Whereโ€™s the fun in that?

Almost sounds like some devilish AI skullduggery!!! :scream: :wink:

1 Like

This one is a super simple script to upload a single or multiple files on 0.0st website it can also a json data of that files with name if need super handy

  • itโ€™s upload your file like
    image

  • i made this because i want to apply skin on my minecraft id from server and i didnโ€™t find anywhere wher i upload my skin easily :sweat_smile::sweat_smile:

A simple sed script, that takes stdin and outputs it in sแดแด€สŸสŸ แด„แด€แด˜s to stdout.

smallcaps:

#!/bin/sed -f

y/abcdefghijklmnopqrstuvwxyz/แด€ส™แด„แด…แด‡๊œฐษขสœษชแดŠแด‹สŸแดษดแดแด˜วซส€sแด›แดœแด แดกxสแดข/

Similarly, a sed script that outputs in ๐–‹๐–—๐–†๐–๐–™๐–š๐–—:

fraktur:

#!/bin/sed -f

y/ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz/๐•ฌ๐•ญ๐•ฎ๐•ฏ๐•ฐ๐•ฑ๐•ฒ๐•ณ๐•ด๐•ต๐•ถ๐•ท๐•ธ๐•น๐•บ๐•ป๐•ผ๐•ฝ๐•พ๐•ฟ๐–€๐–๐–‚๐–ƒ๐–„๐–…๐–†๐–‡๐–ˆ๐–‰๐–Š๐–‹๐–Œ๐–๐–Ž๐–๐–๐–‘๐–’๐–“๐–”๐–•๐––๐–—๐–˜๐–™๐–š๐–›๐–œ๐–๐–ž๐–Ÿ/

And one that gives แšชแ›แ›šแšฉ-แ›‹แšชแ›‰แšฉแšพ แšฑแšขแšพแ›–แ›‹:

anglo-runes:

#!/bin/sed -f

s/./\L&/g
s/q/แ›ฃแšน/g
s/th/แšฆ/g
s/ng/แ›/g
s/ae/แšซ/g
s/ea/แ› /g
s/io/แ›ก/g
s/oe/แ›Ÿ/g
y/abcdefghijklmnoprstuvwxyz/แšชแ›’แšณแ›žแ›–แš แšทแšปแ›แ›„แ›ฃแ›šแ›—แšพแšฉแ›ˆแšฑแ›‹แ›แšขแš แšนแ›‰แšฃแšด/

And, of course, you can make your own.


An example of how they might be used:

fraktur <<< "absolutely proprietary" | xclip -sel c

And just paste it to get โ€œ๐–†๐–‡๐–˜๐–”๐–‘๐–š๐–™๐–Š๐–‘๐–ž ๐–•๐–—๐–”๐–•๐–—๐–Ž๐–Š๐–™๐–†๐–—๐–žโ€.

4 Likes

Well, I use it a lot myself, but mostly with a one liner

curl -F "file=@1.mp4" "https://0x0.st" | wl-copy

but the problem with null pointer(https://0x0.st/) is that you canโ€™t upload anything, and it also includes some mincraft stuffs

I didnโ€™t had any problem with that but sometimes I wanted to share some stuffs which I donโ€™t want to be seen publicly, so I would make a zip file and then add a password to it


 โ•ญโ”€ankur@ankur in ~/something took 1s
 โ•ฐโ”€ฮป zip -r something.zip *
  adding: nothing.txt (stored 0%)
  adding: something.txt (stored 0%)
 โ•ญโ”€ankur@ankur in ~/something took 5ms
 โ•ฐโ”€ฮป zipcloak something.zip 
Enter password: 
Verify password: 
encrypting: nothing.txt
encrypting: something.txt

Beware that they can block your ip address if they feel like you are doing some weirdo things :wink:

I can always keep trying with different VPN servers. :moyai:

2 Likes

This was probably the best script I had been missing in my PC

Tweaked it a little and added it to .profile

export FZF_DEFAULT_OPTS="--height=15 --border=double --padding=1% --info=right --separator=_ --preview='bat {}' --preview-window
=hidden:right:69% --preview-label=eyes --margin=5% --border-label="search" --color=16 --layout=reverse --prompt=๐Ÿซ  --bind='alt-o
:toggle-preview'"

Now it can

  1. Toggle when a keybind is pressed alt+o

Todo: Make preview extension specific i.e pdf files to open with pdf etc.

Thanks for teaching me files can be previewed :heart:
โ€“The editing part not done yet, I still want to see if different files can be opened differently

1 Like

I like the flexibility of pacman, but keeping it under control is a bit tricky for me. I was reviewing all the nvidia files installed and found this is one liner from the ArchWiki pacman/Tips and tricks, section 1.2 helped a lot.

pacman -Qq | fzf --preview 'pacman -Qil {}' --layout=reverse --bind 'enter:execute(pacman -Qil {} | less)'

This produced 3 sections in the terminal, upper left for typing into, and 2 scrollable areas that you could move around in.
There are other variations on this, this was my favorite.

7 Likes

I see this was your first post @ARClite, welcome to the forum and thanks for giving back.

2 Likes

Useful for system monitoring:

watch -n 0.1 journalctl -n 100
watch -n 0.5 sensors
2 Likes