[a / b / c / d / e / f / g / gif / h / hr / k / m / o / p / r / s / t / u / v / vg / vm / vmg / vr / vrpg / vst / w / wg] [i / ic] [r9k / s4s / vip] [cm / hm / lgbt / y] [3 / aco / adv / an / bant / biz / cgl / ck / co / diy / fa / fit / gd / hc / his / int / jp / lit / mlp / mu / n / news / out / po / pol / pw / qst / sci / soc / sp / tg / toy / trv / tv / vp / vt / wsg / wsr / x / xs] [Settings] [Search] [Mobile] [Home]
Board
Settings Mobile Home
/g/ - Technology

Name
Options
Comment
Verification
4chan Pass users can bypass this verification. [Learn More] [Login]
File
  • Please read the Rules and FAQ before posting.
  • You may highlight syntax and preserve whitespace by using [code] tags.

08/21/20New boards added: /vrpg/, /vmg/, /vst/ and /vm/
05/04/17New trial board added: /bant/ - International/Random
10/04/16New board for 4chan Pass users: /vip/ - Very Important Posts
[Hide] [Show All]


[Advertise on 4chan]


File: file.png (133 KB, 1084x512)
133 KB
133 KB PNG
ITT we share scripts/oneliners/functions or any other utils that you use often, they help you and you feel like it could help the others

>inb4 rm -rf /
>any other lame obfusations
>>
>>108478696
magick path/to/image.jpg -colors 10 -define histogram:unique-colors=true -format "%c" histogram:info: | grep -oP '#[0-9A-F]{6}' > ~/path/to/file.txt


i use this oneliner often to extract colors from images. it outputs the colors as clean hex codes separated by newline
>>
>>108478737
anyone here who runs some decent AI models locally that actually help him for specific tasks?
>>
Not exactly a script, but I wrote a utility for launching programs into the background. It's most useful for starting a GUI from a terminal window when you don't want to see the logs, and I do this pretty often.
#define _GNU_SOURCE
#include <spawn.h>
#include <unistd.h>
#include <fcntl.h>

#include <stdio.h>
#include <string.h>

extern char **environ;


int
main(int argc, char **argv) {
if (argc < 2) {
printf("usage: %s <program> [args]\n", argv[0]);
return 1;
}

if (-1 == close_range(3, -1, 0)) {
perror("close_range");
return 1;
}

posix_spawnattr_t attr;
if (posix_spawnattr_init(&attr)) {
perror("posix_spawnattr_init");
return 1;
}
posix_spawnattr_setflags(&attr, POSIX_SPAWN_SETSID);

posix_spawn_file_actions_t acts;
if (posix_spawn_file_actions_init(&acts)) {
perror("posix_spawn_file_actions_init");
return 1;
}
posix_spawn_file_actions_addopen(&acts, 0, "/dev/null", O_RDONLY, 0);
posix_spawn_file_actions_addopen(&acts, 1, "/dev/null", O_WRONLY, 0);
posix_spawn_file_actions_addopen(&acts, 2, "/dev/null", O_WRONLY, 0);

pid_t pid;
int err = posix_spawnp(&pid, argv[1], &acts, &attr, &argv[1], environ);
if (err) {
printf("failed to spawn process: %s\n", strerror(err));
return 1;
}

return 0;
}
>>
>>108478696
this has been the single most helpful script i have ever set up, and it's not even close
https://eli.thegreenplace.net/2013/06/11/keeping-persistent-history-in-bash
i'm not even joking when i say it has completely changed my workflow
>>
File: 1774781571429178.jpg (24 KB, 640x640)
24 KB
24 KB JPG
>>108478696
>Bash
>My main tool at work, even on Sunday
P-Please... I still have 8h+ till work.
>>
>>108478794
That's pretty cool, I'll save this.
You could just use
>program >/dev/null 2>&1 &
And it throws everything to dev/null.
>>
>>108478829
Then your program dies when you close the terminal window, and that gets VERY annoying.
>>
>>108478801
Using fzf to search through base history is nice
>>
>>108478848
Oh yeah didn't remember that. I use gnu screen almost always.
>>
>>108478737
what do you use that for?
>>
>>108478794
2> /dev/null
also disown
>>
>>108478848
>disown
>>
>>108478905
>>108478898
Doesn't set a new session id, and doesn't reparent to init until the terminal closes.
>>
>>108478848
read -t l
>>
>>108478885
making colorschemes
>>
>>108478929
how do you bring that gui program to fg then?
>>
>>108479184
I don't. It just opens in a new window.
>>
>>108479240
why wrestle with session id etc then?
>>
>>108479340
I want the spawned program to have absolutely no relation to the environment it came from, so no parent-child relationship, no shared session ID, and no accidentally inherited file descriptors. I couldn't find a tool to do all that, so I wrote one.
>>
>>108478829
>>108478848
nohup
>>
>>108478696
alias new='ls -ltr -G | tail -20'
>>
File: 2026-03-29_12-06.png (480 KB, 495x1042)
480 KB
480 KB PNG
>>108478696
Not bash, but
https://codeberg.org/problems_available/zsh_config
I should have some stuff in here that works in bash.
(picrel is a filesystem bookmarks function from 9.final.zsh, bound to ctrl-b)
https://codeberg.org/problems_available/scripts
I have a few wrapper scripts in here for fzf and extracting and creating archives, and another for replacing the target file or directory with symlinks linked from the target destination to which the files were copied before being removed and then symlinked, so instead of typing 'cp files destination; rm files; cp -s destination files', you just type 'linkback destination files', confirm that the message reflects the intended operation, then press y to confirm.
https://codeberg.org/problems_available/i3_config/src/branch/home/scripts
Just rofi-input. If you use i3-input, you might like rofi-input.
>>
alias c='clear'
alias d='cd'
alias b='d ..'
alias a='cat'
alias e='echo'
alias f='find'
alias t='touch'
alias x='exit'
alias u='sudo '
alias pm='u pacman'
alias update='pm -Syu'
alias ins='pm -S '
alias remove='pm -R '
alias v='vim'
alias uv='u v'
alias dl='d ~/Downloads'
alias dk='d ~/Desktop'
alias dev='d ~/Downloads/dev'
alias l='ls -lah'
alias s='ls -CAF --color=auto --group-directories-first'
alias pk='pkill -9'
alias watch='watch -n1 '
alias wt='watch '
alias wa='watch a'
alias wtm='wa /proc/meminfo'
alias cp='cp -vi'
alias mv='mv -vi'
alias rm='rm -vI --one-file-system'
alias mkdir='mkdir -pv'
alias df='df -h'
alias du='du -h'
alias du2='du --max-depth=1 | sort -h'
alias du3='du | sort -h'
alias ip='ip --color=auto'
alias rsync='rsync -aiv'
alias grep='grep --color=auto'
alias diff='diff --color=auto'
alias xxd='xxd -a'
alias ag='ag --hidden'
alias dmesg='u dmesg -HL'
###
# git aliases
alias g='git'
...
>>
>>108479877
>save 2 seconds over a month with these simple tricks
>>
>>108479877
con() {
convert $1 a.jpg
}
alias wg='dl && wget '
yt() {
u mv /etc/hosts /etc/hosts2
yt-dlp $@
u mv /etc/hosts2 /etc/hosts
}
ffmp() {
local limit=3.9
local duration=$(ffprobe -v error -show_entries format=duration -of csv=p=0 "$1")
local bitrate=$(echo "$duration" | awk -v limit=$limit '{print int((limit*1024*1024*8)/$1/1000)}')
ffmpeg -i "$1" -c:v libvpx-vp9 -b:v "${bitrate}K" -an -row-mt 1 -pass 1 -f null /dev/null
ffmpeg -i "$1" -c:v libvpx-vp9 -b:v "${bitrate}K" -an -row-mt 1 -pass 2 -f matroska "$1.webm"
rm ffmpeg2pass-0.log
}
alias code='vscodium'
alias py='python'
alias m='time make'
alias mm='time cmake .'
alias n='time ninja'
alias nn='time cmake -G Ninja .'
alias odump='objdump -M intel --no-show-raw-insn -CDSg'
alias odump2='objdump -M intel --no-show-raw-insn --disassembler-color=extended --visualize-jumps=extended-color -CDSg'
alias bindump='odump -b binary -m i386:x86-64'
alias lodump='llvm-objdump -M intel --no-show-raw-insn --symbolize-operands -CDSg'
alias godbolt='d ~/Downloads/dev/godbolt && make run-only'
alias godbolt2='d ~/Downloads/dev/godbolt && make'
diffs() {
echo "Paste first text:"
text1="$(cat)"
echo "Paste second text:"
text2="$(cat)"
clear
diff --color=auto --side-by-side --suppress-common-lines <(echo "$text1") <(echo "$text2")
}
>>
>>108479881
To add tab completion to aliases: https://github.com/cykerway/complete-alias
>>
>>108478696
Still my favourite alias for filtering history

hs='fzf --scheme=history --tac --bind "home:last,end:first,change:first,enter:become:printf -- %s {} | xclip -selection clipboard" < "$HISTFILE"'
>>
>>108479879
I already forgot them all.
>>
File: 2026-03-29_12-51_1.png (350 KB, 641x414)
350 KB
350 KB PNG
>>108479679
linkback shot
>>
>>108479881
>
yt() {
u mv /etc/hosts /etc/hosts2
yt-dlp $@
u mv /etc/hosts2 /etc/hosts
}

Why?
>>
>>108480207
To get around the porn sites he blocked. I'd bet a dollar on it.
>>
>>108480228
Why would you block it if you're going to download from there anyway?
>>
>>108479877
>
alias c='clear'

Ctrl-l exists?
>>
function webm2gif() {
local fps="${2:-20}"
ffmpeg -y -i "$1" -vf palettegen ffmpeg_gif_palette.png
ffmpeg -y -i "$1" -i ffmpeg_gif_palette.png -filter_complex paletteuse -r $fps "${1%.*}.${fps}fps.gif"
}

tfw there are still fucking places on the planet that can't take webms
>>
>>108480257
For the wife. Not my function, but either they want to show that they have blocked the sites to someone, or they just made a way around it so they wouldn't feel as bad as if they would if they unblocked the sites.
>>
>>108480257
If the latter, it probably started out as a one-liner in their command history before they finally made it into a function.
>>
>>108478696
>A REPL for sdcv (cli for stardict)
# sdcv REPL
function sdcr() {
[ $# -gt 0 ] && pmt="$@" || \
read '?> ' pmt
while true; do
sdcv "$pmt" 2>&1 | \
fold -s | \
less
read '?> ' pmt
done
}


>mkdir && cd for ZSH, might work for other shells idk
function mkdcd() { mkdir "$@" && cd ${*: -1} }
>>
>>108480372
What's the purpose of '${*: -1}'?
>>
>>108480372
Oh, it's so you can pass flags.
>>
Only command I ever run on the terminal anyways

alias update='distrobox upgrade --all;flatpak update;rpm-ostree upgrade'
>>
>>108478811
it'll be ok anon. dubs confirm something good will happen to you next week
>>
>>108478811
If you don't have fun doing this why the hell are you here? Why the hell did you pick tech as a job?
>>
>>108478794
just use setsid <program>

or fork() + exec*() + setsid() the child, at least it's the standard unix way

>>108480539
${*} expands all arguments given to the function or program, performing optional expansion inside each argument. Unlike ${@} which doesn't expand inside arguments, e.g
stuff() { printf '%s\n' ${*}; } 
stuff hello world # displays hello\nworld
stuff "hello world" # displays hello\nworld

stuff() { printf '%s\n' ${@}; }
stuff hello world # displays hello\nworld
stuff "hello world" # displays hello world


The :-1 part is for default arguments, if ${*} is empty, then it's replaced with '1', The `-` makes the expansion of the default argument lazy:
f() { printf '%s\n' ${*:-$HOME}; }
f # /home/user
f() { printf '%s\n' ${*:$HOME}; }
f # bash: *: /home/user: arithmetic syntax error: operand expected (error token is "/home/user")


you can read the manual, but bash parameter expansion is huge:
https://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html
>>
>>108480539
>>108481230
fuck I misread the space in ${*: -1}

it's array indexing notation, it looks up the last element of ${*}, which is probably so that you can pass flags to mkdir and have cd ignore them and only use the last argument as the path.

it doesn't work because 'mkdcd "foo bar"' would try to 'cd foo bar' which is two arguments. It should be wrapped inside "" for bash. But ZSH's expansion allows this sort of stuff.

that reminds me, of some coworker who spend an entire day figuring out why his program wouldn't run, when he found out ZSH was doing some weird expansion with the program args.
>>
>>108480328
nta, but I block most google domains in my unbound config, I guess that would make sense
>>
>>108481275
Yeah zsh is like that. I always forget the exact caveat.
>>
>>108480283
We moved on (started at, really) mp4.
Webm never had a purpose, like webp
>>
>>108481324
webm are better for streaming/web.
this site also has better compression support for webms compared to mp4.

if we could post av1 mp4, I wouldn't complain, but you can fit way more quality into 4MB of VP9 than into 4MB of h264
>>
>>108478696
why does everything need a fucked corporate logo these days
>>
>>108481334
> quality
Yes, I post all my final-form indie feature films into 4chan
>>
>>108478794
you know you can just...
example-program &> /dev/null & disown
right?
>>
>>108481601
>just
More hassle to type, and
>doesn't automatically reparent to init
>doesn't reset session id
>doesn't close other file descriptors
>>
>>108478794
i didn't know about spawn, thanks. learned a lot.
>>
>CLI
lmao..
>>
>>108481645
use case for any of that shit? you know you can just make that a function in your bashrc, right?
>>
>>108481713
when you could just have used setsid <program> instead?
>>
>>108478696
My favorite one is
claude
>>
>>108482006
hello sir
>>
>>108478811
bash is great for programming in tho
it's so capable yet high level, it's honestly my favorite language when the usecase allows
>>
>>108484162
Bash is a lot of fun, even if the syntax is a bit haphazard sometimes.

${!dict[@]} hmm yes that's how I want to get all the keys in my assarray
>>
>>108478787
>>>/g/vcg/
>>108478851
Another anon said to use C-r (better with fzf) and it made my life way better, especially when I’m not using fish
>>
>>108480372
why not just
mkdir DIRNAME && cd $_

?
>>
De-minify youtube URLs (if you need it for whatever reason)
sed -i -E 's|youtu\.be/([a-zA-Z0-9_-]+)|www.youtube.com/watch?v=\1|g
'
>>
>>108484253
>/g/vcg/
what?

also atuin or mcfly
>>
>>108485026
>/g/vcg/
>what?
Lurk more, faggot. That is a general discussion full of people that run local models that help them do stuff. >>108478787
>>
Here are some of my fav aliases. I also have a few aliases to prevent some commands from populating my $HOME. Would recommend xdg-ninja to help you clean up $HOME.

# macOS inspired copy/paste commands
alias pbcopy="xclip -selection c"
alias pbpaste="xclip -o -selection clipboard"

# Incognito mode.
alias anon="export HISTFILE='' && echo 'Incognito mode activated'"

# yt-dlp commands for downloading best video and audio
alias ytdl="yt-dlp -f 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best'"
alias ytdla="yt-dlp -x --audio-format mp3 --audio-quality 0"

alias se="sudoedit"
alias hosts="sudoedit /etc/hosts"

# Start a simple http server
alias www="ls && sudo python3 -m http.server 80"

alias open="xdg-open"
>>
I really wish all devs would respect the XDG base directories to prevent clutter in $HOME.

I kinda want to start a group to push patches to software to support this because other devs wont prioritize it.

https://wiki.archlinux.org/title/XDG_Base_Directory
>>
File: soybash.png (288 KB, 1090x981)
288 KB
288 KB PNG
>>108478696
God, I hate BASH so much.
>>
>>108484309
I didn't know that, thanks.
>>
Be in bash. Cursor is in the middle of a longish line. I wish to delete everything to the left of the cursor. Hit control-u.
>>
I love bash, and if it makes nigger faggots like this retard here >>108485243 seethe then it only makes me love it wven more
>>
>>108485042
why the fuck you even bring ai into this thread you mongoloid?

>also calling someone faggot while clearly being fag of the month
>>
>>108485243
skill issue
>>
File: conv.png (3 KB, 218x97)
3 KB
3 KB PNG
convert number to dec hex bin
conv() {
local in="$1"
local dec
case "$in" in
0x*|0X*) dec=$((in)) ;; # hex 0xFF
0b*|0B*) dec=$((2#${in:2})) ;; # bin 0b1010
0[0-7]*) dec=$((in)) ;; # oct 0755
*) dec=$((in)) ;; # dec
esac
printf "dec: %d\n" "$dec"
printf "hex: 0x%X\n" "$dec"
printf "bin: %s\n" "$(echo "obase=2; $dec" | bc)"
>>
>>108485369
>why the fuck you even bring ai into this thread you mongoloid?
Are you retarded or a collection of 0s & 1s?
tl;dr
>>108478787
anyone here who AIs?(You)
>>108484253
links to a general discussion of people who AIs(Wise Anon)
>>108485026
hurr durr what(You)
>>108485042
git gud, dummy(ME)
>>108485369
I am a huge faggot, please rape my face.(You)

fuck off, faggot
>>
>>108485414
This is very useful. Thank you.
>>
>>108485452
Seek help and silently fuck off this thread.
>>
>>108485466
rofl, you are the one on display, faggot.
>>
>>108485232
I loathe xdg because it forces you to split app data across many different folder roots. it's almost as bad as windows's appdata roaming locallow garbage.
data and state should've never been two folders, that's horrendous. config should be linked to in the master nix configuration file. if it can't be declaratively and purely functionally written it should live in the data folder. runtime should just be a symlink to tmp or /var/run.
however a more persistent, program-managed cache can be useful and that's how android does things too.
>>
>>108478696
>Bash
Disgusting excuse of a language
p='"M 25 25 l -150 0 l 0 -150 l 50 0 l 0 100 l 100 0 Z"' r='rotate degrees=90' bash -c 'gegl -- fill-path color=#000 d="$p" $r dst-over fill-path color=#000 d="$p" $r dst-over fill-path color=#000 d="$p" $r dst-over fill-path color=#000 d="$p" $r rotate degrees=45 dst-over dst-over aux=[ fill-path color=#FFF d="M 200 0 C 200 110.46, 110.46 200, 0 200 C -110.46 200, -200 110.46, -200 0 C -200 -110.46, -110.46 -200, 0 -200 C 110.46 -200, 200 -110.46, 200 0 Z" ] dst-over aux=[ rectangle x=-480 y=-280 width=960 height=540 color=#C11 ]'
>>
_cd () {
builtin cd -- "$@" && COLUMNS=$COLUMNS ls \
--sort=time \
--format=across \
--color=always \
--almost-all \
--indicator-style=slash \
| head -$(( LINES - 1 ))
}


Shows the recently modified files when you cd into a dir.
>>
>>108487024
very short and easy to remember, thanks anon
>>
>>108487024
You could just write a hook for your prompt that does that every time PWD changes.
>>
>>108478696
Why? If I need anything I will just ask the AI to make a script for me. Do you have some text file with all the l33t shell scripts you found like some boomer? Unc
>>
>>108487072
True, might look into that actually
>>
>>108478696
Made this to keep track of streamers on Youtube and Twitch. It logs them in terminal and shows a little pop up with kdialog when a stream starts.

#!/usr/bin/env bash

set -euo pipefail

[[ "${1-}" == "--help" ]] && echo "Usage: ${0##*/}" && exit

streamer_list_twitch=(
"https://www.twitch.tv/streamer"
)

streamer_list_youtube=(
"https://www.youtube.com/@streamer/live"
)

fn_get_streams_status () {
yt-dlp --print "%(uploader)s - %(description)s - %(webpage_url)s" "${streamer_list_twitch[@]}" 2>/dev/null || true
yt-dlp --sleep-requests 10 --print "%(uploader)s - %(fulltitle)s - %(webpage_url)s" "${streamer_list_youtube[@]}" 2>/dev/null || true
}

fn_find_new_streamers () {
local s t
for s in "${streamer_list[@]}"; do
for t in "${streamer_list_old[@]}"; do
[[ "$s" == "$t" ]] && continue 2
[[ "$s" != "$t" ]] && continue
done
printf '%s\n' "$s"
done
}

streams_list_old=()
streamer_list_old=()
printf -v current_hour_old '%(%H)T'

while true; do
mapfile -t streams_list < <(fn_get_streams_status)
mapfile -t streamer_list < <(printf '%s\n' "${streams_list[@]%% - *}")
mapfile -t new_streamers < <(fn_find_new_streamers)
printf -v current_hour '%(%H)T'

if [[ "${streams_list[*]}" != "${streams_list_old[*]}" ]]; then
printf -- '\e[1m---%(%F %T)T---\e[0m\n'

[[ -n "${new_streamers[*]}" ]] && (IFS=$'\n'; kdialog --passivepopup "Streams live:\n${new_streamers[*]}" 30)

streams_list_old=("${streams_list[@]}")
streamer_list_old=("${streamer_list[@]}")

if [[ -n "${streamer_list[*]}" ]]; then
printf '%s\n' "${streams_list[@]}"
else
printf '%s\n' "All streams offline"
fi
fi

[[ "$current_hour" != "$current_hour_old" ]] && printf '%s\n' "."

current_hour_old="$current_hour"

sleep 30
done
>>
bump for bash the trannies and miggers.
>>
>>108482006
I ain't going to lie, Claude has helped me learned a lot and troubleshoot Lonux
>>
alias z=zellij
alias za="zellij attach \$(zellij list-sessions | fzf | awk '{print $1}')"
alias zd="zellij delete-session \$(zellij list-sessions | fzf | awk '{print $1}')"
alias zk="zellij kill \$(zellij list-sessions | fzf | awk '{print $1}')"
alias zw="zellij watch \$(zellij list-sessions | fzf | awk '{print $1}')"
>>
>>108490218
oops. needs to be 'print \$1'
sorry
>>
>>108478696
#!/usr/bin/env sh

echo Good Morning


$ ./good_morning.sh
Good Morning
>>
>>108490218
I fixed them.
alias z=zellij
alias zs="zellij -s"
alias ze="zellij e"
alias zc="zellij r"
alias za="zellij a \$(zellij list-sessions | fzf | awk '{print \$1}')"
alias zd="zellij d \$(zellij list-sessions | fzf | awk '{print \$1}')"
alias zk="zellij k \$(zellij list-sessions | fzf | awk '{print \$1}')"
zkd() {
local session="$(zellij list-sessions | fzf | awk '{print $1}')"
zellij k $session
zellij d $session
}
alias zw="zellij w \$(zellij list-sessions | fzf | awk '{print \$1}')"
>>
gets the current gateway's IP
export PHONEIP=$(ip route | grep default | awk '{print $3}')
>>
alias folder='powershell.exe -Command "Invoke-Item ."'
alias paste='powershell.exe -Command "Get-Clipboard"'


from wsl if I had to use windows
>>
>>108478794
God, I love C. Memory safety is for wimps. Give me that Sweet, Clean Speed.
>>
>>108492535
Fixed em even harder
zz() {
local num=0
while zellij list-sessions 2>/dev/null | grep -q "^session${num} "; do
((num++))
done
zellij a --create "session${num}"
}
zt() {
local num=0
while zellij list-sessions 2>/dev/null | grep -q "^nvimterm${num} "; do
((num++))
done
zellij -l nvimterm a --create "nvimterm${num}"
}
zv() {
local num=0
while zellij list-sessions 2>/dev/null | grep -q "^nvim${num} "; do
((num++))
done
zellij -l nvim a --create "nvim${num}"
}

~/.config/zellij/layouts/nvim.kdl
layout {
default_tab_template {
pane size=1 borderless=true {
plugin location="zellij:tab-bar"
}
children
pane size=1 borderless=true {
plugin location="zellij:status-bar"
}
}

tab {
pane {
command "nvim"
args "-S" "Session.vim"
}
}
}

~/.config/zellij/layouts/nvimterm.kdl
layout {
default_tab_template {
pane size=1 borderless=true {
plugin location="zellij:tab-bar"
}
children
pane size=1 borderless=true {
plugin location="zellij:status-bar"
}
}

tab {
pane {
command "nvim"
args "+te"
}
}
}
>>
>>108480281
doesn't clear the scrollback!
>>
>>108493114
then use "reset"
>>
File: images.jpg (15 KB, 256x197)
15 KB
15 KB JPG
I don't quite remember why my systray applet for the battery stopped working so back then (like a year ago) I made a quick command to get the battery level on the terminal as a quick workaround to know if I had to rush to a power outlet. Got lazy and never looked for a new applet.
alias batt="upower -d | grep percentage | uniq | sed 's/.........................//'"


>>108479679
Font name?

>>108479877
Never thought about doing this with du and df, thanks anon.

>>108490309
At least try to use whatever xterm + w3m magic is needed to make it print picrel
>>
>>108493170
also uhhh, the sed command is ass. It doesn't needs to look that shitty. But I didn't knew RE back then and so I did what I had to.
>>
>>108487024
I've just aliased ls to include these options
>>
>>108493114
How about if you Ctrl+L x2?
>>
>>108493114
>>108493247
bind -x '"\C-l":"clear"'
>>
>>108493247
thats new to me, thx
>>
>>108493415
Is that really a thing? I thought it was a joke because it doesn't work for me
>>
>>108493458
tested is now again - ur right
reset does the job
>>
>>108493040
These functions are fucked up, they don't increment properly. Shouldn't have raw-dogged grok.
>>
>>108493170
iosevka custom build
https://codeberg.org/problems_available/configs/src/branch/home/private-build-plans.Wub.toml
>>
>>108493538
I am so sorry for shitting this thread up with my fucked up functions. Here is the final version of my zellij functions.
I have to do this.
zz() {
local session="session0"
highest=$(zellij list-sessions | grep -oE 'session[0-9]+' | sed 's/session//' | sort -n | tail -1 2>|/dev/null)
if [[ -n "$highest" && "$highest" =~ ^[0-9]+$ ]]; then
local session="session$((highest + 1))"
fi
zellij a --create "$session"
}
zt() {
local session="nvimterm0"
highest=$(zellij list-sessions | grep -oE 'nvimterm[0-9]+' | sed 's/nvimterm//' | sort -n | tail -1 2>|/dev/null)
if [[ -n "$highest" && "$highest" =~ ^[0-9]+$ ]]; then
local session="nvimterm$((highest + 1))"
fi
zellij a --create "$session"
}
zv() {
local session="nvim0"
highest=$(zellij list-sessions | grep -oE 'nvim[0-9]+' | sed 's/nvim//' | sort -n | tail -1 2>|/dev/null)
if [[ -n "$highest" && "$highest" =~ ^[0-9]+$ ]]; then
local session="nvim$((highest + 1))"
fi
zellij a --create "$session"
}
>>
>>108493940
I still fucked them up because I forgot to add the fucking layouts.
>>
rofi_input
#!/bin/env bash

rofi -config ~/.config/rofi/input.config.rasi -dmenu -p "$1"


tipremind
#!/usr/bin/env bash
while [[ $# -gt 0 ]]; do
case "$1" in
-s|--start)
while :
do notify-send "$(cat ~/.config/tipremind/tipremind.txt|shuf -n 1)"
sleep "$2"
done
;;
-a|--append)
rofi-input "reminder" >> ~/.config/tipremind/tipremind.txt
;;
-l|--list)
cat ~/.config/tipremind/tipremind.txt | nl -ba | rofi -dmenu
;;
-d|--delete)
linenum=$(cat ~/.config/tipremind/tipremind.txt | nl -ba | rofi -dmenu | awk '{print $1}')
if [[ -n "$linenum" && "$linenum" =~ ^[0-9]+$ ]]; then
sed -i "${linenum}d" ~/.config/tipremind/tipremind.txt
fi
;;
-k|--kill)
killall -9 tipremind
;;
esac
shift
done
>>
>>108494517
Ironically. I forgot what I wanted to remember that prompted me to make this. I should have just written it down.
>>
# keep aliases on sudo https://serverfault.com/a/178956
alias sudo='sudo '

# prompt
case "$USER" in
root)
PS1='\[\033[01;31m\]\h\[\033[00m\] \[\033[01;34m\]\w ${?#0}#\[\033[00m\] '
;;
anon)
PS1='\[\033[01;32m\]\h\[\033[00m\] \[\033[01;34m\]\w ${?#0}>\[\033[00m\] '
;;
*)
PS1='\[\033[01;33m\]\h(\u)\[\033[00m\] \[\033[01;34m\]\w ${?#0}>\[\033[00m\] '
;;
esac

# window title
PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*} ${PWD/#$HOME/\~}\007"'

# ~/bin and ~/.local/bin (pip path)
if test -d $HOME/.local/bin; then PATH=$HOME/.local/bin:$PATH ; fi
if test -d $HOME/bin; then PATH=$HOME/bin:$PATH ; fi

# history settings
HISTCONTROL=ignoreboth
HISTSIZE=9999
shopt -s histappend

# anti-dyslexia settings
shopt -s dirspell
shopt -s cdspell

# update window size after each command
shopt -s checkwinsize

# which which?
alias which="command -v"

# no nano
if which vim &> /dev/null ; then
export EDITOR="vim"
# while we're at it, alias vim to vi
alias vi="vim"
elif which vi &> /dev/null ; then
export EDITOR="vi"
fi

# aliases
alias ls='ls --color=auto -CF'
alias ll='ls -l --color=auto -CF'
alias diff="diff --color=auto"
alias hd='hexdump -C'
alias grep='grep --color=auto'
alias egrep='grep -E --color=auto'
alias rigrep='grep --color=auto -Ri'
alias sprunge="curl -F 'sprunge=<-' http://sprunge.us"
alias bye="sudo poweroff"
alias brb="sudo reboot"
alias pls='sudo $(fc -ln -1)'
alias journalctl="journalctl -a"
alias cal="ncal -Mb"
alias nofnkeys="setxkbmap -option srvrkeys:none"

# mkdir&&cd
md() {
mkdir -p "$@" ;
cd "$@" ;
}

..() {
local dir
local i
local levels="${1:-1}"

for ((i = 0; i < levels; i++)); do
dir+="../"
done

cd "$dir"
}

# prefer ncat over nc
if which ncat &> /dev/null ; then
alias nc=ncat
fi

>>
>>108494748
# prefer content-disposition on wget
unalias wget &> /dev/null || true
if which wget &> /dev/null ; then
alias wget="wget --content-disposition"
else
# in platforms with no wget, use curl as equivalent
if which curl &> /dev/null ; then
wget () {
echo "WARNING: Using curl as wget equivalent" ;
curl -JL --remote-name-all "$@" ;
}
fi
fi

# make zstd behave traditionally
alias zstd="zstd --rm"
alias unzstd="unzstd --rm"

# git stuff
alias gps="git push"
alias gpl="git pull"
alias gc="git commit"
alias gadd="git add"
alias gst="git status"
alias glog="git log --pretty=format:\"%ar - %an - %s\" --graph"

# docker stuff
dosh() {
docker exec -it "$@" /bin/sh -c '
for shell in /bin/bash /bin/ash /bin/sh; do
[ -x "$shell" ] && exec "$shell"
done
'
}

dosu() {
dosh -u root "$@"
}

dorsh() {
docker run --rm -it --entrypoint=/bin/sh "$@" -c \
'
for shell in /bin/bash /bin/ash /bin/sh; do
[ -x "$shell" ] && exec "$shell"
done
'
}

if which docker-compose &> /dev/null; then
alias docker-compose="docker-compose --compatibility"
else
alias docker-compose="docker compose --compatibility"
fi
alias d-c="docker-compose"
alias d-r="docker-compose down && docker-compose up --build -d && docker-compose logs -f"

alias dops="docker ps"

alias dlog="docker logs --since="$(date +%s -dyesterday)""
alias dlogf="docker logs -f --since="$(date +%s -dyesterday)""

alias dlogg="docker logs"
alias dlogff="docker logs -f"

alias dopss="docker ps --format 'table {{.ID}}\t{{.Names}}\t{{.Image}}\t{{.Status}}\t{{.State}}\t'"

# if i'm dumb enough to have sl installed, be nice
if which sl &> /dev/null; then
alias sl="sl -e"
fi
>>
>>108494757
# funny stuff
if test $UID -ne 0; then
alias tableflip="echo '(°□°)︵ ━'"
alias tabledown="echo '─ノ( º _ ºノ)'"
alias shrug="echo '¯\_(ツ)_/¯'"
if which thefuck &> /dev/null ; then
eval $(thefuck --alias)
else
alias fuck=tableflip
fi
alias shit=tableflip
alias crap=tableflip
fi

# greet
if which fortune &> /dev/null ; then
fortune -a
fi

>>
>>108494517
updated start case
    -s|--start)
(
exec -a tipremind bash -c '
while :; do
notify-send "$(cat ~/.config/tipremind/tipremind.txt|shuf -n 1)"
sleep "'"$2"'"
done
'
)
;;
>>
>>108494907
Example in i3:
exec_always pkill -f tipremind
exec_always tipremind -s 90

bindsym $mod+mod1+backslash exec tipremind -a
bindsym $mod+ctrl+backslash exec tipremind -d
>>
Some readline stuff

bind "set show-all-if-ambiguous on"             # Tab completion with only one tab
bind "set active-region-start-color \e[1;32m" # Paste/search highlight: bold green
bind "set active-region-end-color \e[0m" # Highlight end
bind "set completion-ignore-case on" # Case insensitive tab completion
bind "set search-ignore-case on" # Case insensitive ctrl+r search
bind "set colored-stats on" # Coloured files/dirs
bind "set enable-bracketed-paste on" # Avoid accidentally running pasted commands
bind "set mark-symlinked-directories on" # Enable slash auto completion for symlinks
bind "set revert-all-at-newline on" # Don't edit command history if cancelled
>>
File: 1764447006626408.png (225 KB, 480x360)
225 KB
225 KB PNG
>>108486731
Holy shit don't run this there's nerve gas coming out of my PC
>>
make a new tmux session called main if it doesn't already exist, this is at the top of my config
[[ -z $TMUX ]] && exec tmux new-session -A -s main
>>
zf() {
alias zfconfig="fzf --preview='nvimpager -c ~/.config/zsh/zellij_fzfkeys' --bind='\
alt-w:execute<zellij w {+1}>+reload-sync<zellij ls>,\
alt-k:execute<zellij k {+1}>+reload-sync<zellij ls>,\
alt-d:execute<zellij d {+1}>+reload-sync<zellij ls>'"
zellij a $(zellij ls | zfconfig | awk '{print $1}' )
}

bindkey -v '^G' zf-widget
bindkey -a '^G' zf-widget

zf-widget() {
zf
zle reset-prompt
}

zle -N zf-widget
>>
>>108478696
# Sometimes I forget I'm not at vim
alias :e='vim'

# I really fuckign liked how DOS did it
alias cd..='cd ..'
alias cd...='cd ../..'
alias cd....='cd ../../..'
alias cd.....='cd ../../../..'
# I could keep going, I should keep going

# I did this one years ago on a long lost .bashrc, redid here with vibe, it added tests and edge case stuff
mkcd() {
if [ $# -eq 0 ]; then
echo "Usage: mkcd dir1 [dir2 ... dirN]"
return 1
fi
mkdir -p -- "$@"
cd -- "${@: -1}" || return
}


I also had a mkscript on that old bashrc I lost, but I haven't needed it in quite a while. It wrote "#!$(which $1)" on the first line and chmod u+x. It could take several parameters past the first as well. Never needed to redo it.
>>
>>108495561
And zellij wouldn't work with neovim so I moved back to tmux:
t() {
local session="session0"
highest=$(tmux ls | grep -oE 'session[0-9]+' | sed 's/session//' | sort -n | tail -1 2>|/dev/null)
if [[ -n "$highest" && "$highest" =~ ^[0-9]+$ ]]; then
local session="session$((highest + 1))"
fi
tmux new -s "$session"
}
tt() {
local session="nterm0"
highest=$(tmux ls | grep -oE 'nterm[0-9]+' | sed 's/nterm//' | sort -n | tail -1 2>|/dev/null)
if [[ -n "$highest" && "$highest" =~ ^[0-9]+$ ]]; then
local session="nterm$((highest + 1))"
fi
tmux new -s "$session" -- nvim +te
}
tv() {
local session="nvim0"
highest=$(tmux ls | grep -oE 'nvim[0-9]+' | sed 's/nvim//' | sort -n | tail -1 2>|/dev/null)
if [[ -n "$highest" && "$highest" =~ ^[0-9]+$ ]]; then
local session="nvim$((highest + 1))"
fi
tmux new -s "$session" -- nvim -S Session.vim
}

alias ta="tmux attach -t \$(tmux ls |fzf| awk '{print \$1}')"
alias tw="tmux attach -t \$(tmux ls |fzf| awk '{print \$1}') -r"
alias tr="tmux rename-session -t \$(tmux ls |fzf| awk '{print \$1}')"
alias td="tmux kill-session -t \$(tmux ls |fzf| awk '{print \$1}')"

At least i have these functions, though, amirite?
>>
>>108495595
I've done cd.. for years.
>>
mkpushd() {
mkdir -p $1
pushd $1
}
alias mkp=mkpushd

It's all you need.
>>
>>108496640
Sometimes I want to:
mkcd a b c d

Pushing could make me able to pop and visit the others as well, which could be nice, but I'm not used to pushd/popd worflow.
>>
>>108495595
>>108496473
DOSKEY up2=cd ../..
DOSKEY up3=cd ../../..
DOSKEY up4=cd ../../../..
DOSKEY up5=cd ../../../../..
>>
>>108478737
cute,I had no idea you could use magick for this
saved
>>
>>108495595
>>108496473
Congrats on graduating from the Klossacademy
>>
>>108496688
at that rate, it's not to much to just explicitly move.
If I'm making more than one dir, and then moving into one, i'll just type that all out. Not a big deal at that point.
I use zsh with the autocd and autopushd options. It's less of a push/pop "workflow" and more of just being able to pop whenever as an alternative to ../
>>
>>108496710
Kek, I remember her meme. I don't watch ecelebs, I just fucking used DOS a lot before Windows 95 and Linux. Muscle memory could never add a space there.

>>108496731
Yeah, I know I coudl type it out. Most of the time I do use with one folder, but a few times I do a couple, and having the function manage that case is trivial anyway. Again, I'm muscle memoried into my mkcd syntax.
>>
>>108496745
iktf.
I have 'cls' aliased because my hands still type it before my mind remembers that it's a DOS command.
>>
>>108496898
>cls
Me too, bro. I kept it out of my first reply, but I'm adding it here:

alias cls='for i in $(seq $(dc -e "$(echo $LINES 2 - p)")); do echo; done'

I like this more than clear, because sometimes I need to scroll back, and I want to know where I cleared the screen.

I kept it out because I made a dumb mix up. I actually cls at the end of my .bashrc on this machine, whereas another I have it call ~/bin/catasc.bash, a vibecoded bash script to cat some ascii art. It checks lines and columns of the file, and centers it. Displays a nice logo. I didn't want to include that whole script, so I mistankenly removed cls as well as catasc in my first reply.
>>
>>108496945
Interesting.
What's your use case for needing to know where you cleared at?
>>
>>108497003
Sometimes I'm scrolling back to see the output of some old command, and the cls breaks make it easier to find it. I have some idea when I cleared and when I did lots of commands in a row and when it was just one command with very long output. That kind of thing. Sometimes I could rerun the command, but sometimes I want to know what it said that one time and not what it'll say now.
>>
>>108497051
Ah, I see what you mean.
Actually, now that you mention it, I can think of a few instances where that would have been helpful.
>>
>>108497097
Thanks. It's also why I do $($LINES 2 -), to keep space for my two liner colored prompt. Colored prompts really help finding stuff like that, and the first line never get's filled, so it's usually a cleanish line separating the commands as well. Second line is just blue [$]
>>
>>108497141
And it keeps the prompt at the bottom. I like it that way. I mean, I could waste two empty lines as well instead of that dc, but idk, probably some OCD autismo.
>>
>>108495595
>
# I really fuckign liked how DOS did it
alias cd..='cd ..'
alias cd...='cd ../..'
alias cd....='cd ../../..'
alias cd.....='cd ../../../..'
# I could keep going, I should keep going


just turn this into a function wtf
>>
>>108485218
what are you using www for? just curious
>>
>>108497165
How? Most of the time I just do "cd..", and the main benefit is the no need to press space. I'd have to make a custom function to check invalid commands if they match "cd.+", and then if not, call the regular check invalid commands "not found, but avalable for install at ..." which I don't really want to touch. And I don't like to have it waste cycles checking for cd........ at every unrelated invalid command.
>>
>>108497165
Bash doesn't work that way.
Why don't you demonstrate the function you think would achieve the result anon wants (essential: there must not be a space between cd and the dots).
>>
>>108496710
I was using cd.. before she was born.
>>
>>108497183
>>108497188
here you go. maybe some bugs i dunno i'm drunk

cmd="cd "
deeper="../"

chgfun() {
local input="${BASH_COMMAND%% *}"
for (( i = 2; i < ${#input} ; i++)); do
if [[ "${input:$i:1}" == "." ]]; then
cmd+="$deeper"
fi
done
eval "$cmd"
cmd="cd "
}
cdmacro() {
trap - DEBUG
local input="${BASH_COMMAND:0:3}"
if [[ "$input" == "cd." ]]; then
chgfun
fi
trap 'cdmacro' DEBUG
}


command_not_found_handle() {
if [[ "$1" =~ ^cd.+ ]]; then
return 0
else
printf "bash: %s: command not found\n" "$1" >&2
return 127
fi
}
trap 'cdmacro' DEBUG
>>
>>108478794
you know u can just follow a command with an ampersand and it will detach.
>>
this is how i start/restart my emacsclient.
#!/usr/bin/env -S guile -e main
!#

(define pid "emacsclient -e '(emacs-pid)' > /dev/null 2>&1")

(define kill "emacsclient -e '(kill-emacs)'")

(define start "emacs --daemon")

(define (main _)
(when (zero? (system pid))
(system kill))
(system start))
>>
Silly smily
:(){:|:&};:
>>
>>108497986
modern shells are wise to fork bombs.
i think i got it to work on an ubuntu10 vm a few years ago.
>>
>>108497183
>>108497904
>spends two hours and a half to create what I specifically said I could have done back when I first moved to linux, but chose not to
>just to win some internet argument, apparently
Congratulations, I guess?
>>
>>108498008
i had fun making it ( ._.)
>>
>>108497904
>>108498008
laughs in zsh
alias -g ...="../.."
alias -g ....="../../.."
alias -g .....="../../../.."
alias -g ......="../../../../.."
alias -g .......="../../../../../.."
alias -g ........="../../../../../../.."

I don't even use it. I just thought it would be funny.
>>
>>108478696
I have some nooby stuff for smartctl, dd, and something else. It’s like they made these tools with scripters in mind
>>
>>108498031
I know you had. It is fun, I did it back then once and opted to delete the whole thing. The congrats were half assed but genuine.

>>108498035
I'm unfamiliar with zsh. Does this work without spaces between cd and the dots? Would this expand the dots on other commands like ls.... where it shouldn't? I don't see where it restricts those to only work on cd. Also, the fact that you had to do one for each level, means it doesn't really have much advantage over the original back on >>108495595
>>
File: 6be46451c7.png (736 KB, 1080x1233)
736 KB
736 KB PNG
Sometimes I download an image from the net just to use it on my post, but for some reason 4chan complains about it, so instead I created this script and put it on my .bashrc:
i2p() {
local input="$1"

[[ -f "$input" ]] || { echo "Usage: img2png <image>"; return 1; }

local hash
hash=$(sha256sum "$input" | cut -c1-10)

ffmpeg -y -i "$input" "${hash}.png"
}


It used to have a bigger name like image2png, which was stupid and I got tired of typing it, so now it's just "i2p" + filename. Outputs the image with a generated hash for its name.
>>
>>108498035
i have this up to 100 layers just because it's funny
>>
>>108497977
i realized the irony of writing this in guile, when i could have just used emacs.
#!/usr/bin/env -S emacs --script

(defvar pid "emacsclient -e '(emacs-pid)'")

(defvar kill "emacsclient -e '(kill-emacs)'")

(defvar start "emacs --daemon")

(defun main ()
(let ((inhibit-message t))
(when (zerop (shell-command pid))
(shell-command kill)))
(message "%s" (shell-command-to-string start)))

(main)
>>
>>108497942
See >>108478848, >>108479380, and >>108478929.
>>
>>108498065
The example I showed is using a global alias. Global aliases, as the name suggests, can be used anywhere, in place of a command or an argument. With autocd enabled, you don't even have to type cd, but bash has autocd as well, just not global aliases or autopushd.
>>
>>108478696
i use it to sandbox stuff and give it access to the pwd, ie meme vibecode shit.
ie alias opencode = "sb npx opencode"
#!/usr/bin/env bash
sandbox=~/.local/share/sandboxes/sandbox
mkdir -p $sandbox
PWD="$(realpath $PWD)"
PWDARG="--bind $PWD $PWD"

if [ "$PWD" == "$HOME" ]
then
echo PWD is HOME, not binding it
PWDARG=""
fi

bwrap \
--ro-bind /bin /bin \
--ro-bind /lib /lib \
--ro-bind /lib64 /lib64 \
--ro-bind /etc /etc \
--ro-bind /sbin /sbin \
--ro-bind /usr /usr \
--ro-bind /run/systemd/resolve /run/systemd/resolve \
--dev /dev \
--tmpfs /tmp \
--proc /proc \
--bind $sandbox $HOME \
$PWDARG \
--die-with-parent \
--unshare-all \
--share-net \
$@
>>
>>108478801
>ctrl + f
>no mention of ~/.bash_history
Is that an April Fools' joke?
>>
>>108478811
If you don't want to do it 24/7 like the rest if us, why do it at all?
>>
>>108500355
Look at this clueless retard.
>>
>>108499960
I don't really understand what he's going for here either. It's like he's using some alternate reality Bash that works the opposite mine does. History is loaded when you start Bash and doesn't get overwritten by other sessions by default.
>>
>>108500502
I didn't run his code, but it sounds like he just harcoded default behavior.
>>
>>108500650
this has me thinking, though. It would be nice to have a seperate history file for when I'm repling out multiliners and scripts.
>>
>>108499960
>>108500502
>>108500650
June 11, 2013 at 19:27
>>
>>108499952
Neat. I personally prefer to untrusted shit inside a VM with no internet access (or behind a Tor tunnel).
>>
>>108500686
I'm not old enough to know what was different about Bash in 2013
>>
>>108500686
I didn't think eli the computer guy was an idiot (at least not enough to totally make up reasons for doing that to his bashrc,)
>>
>>108500702
same, but for the webslop shit i do it's enough.
i don't get people running opencode on their home directory with no form of isolation.
also you can remove --share-net at the end and it'll have no networking access, not even your localy bound processes.
>>
this is in fish, but whatever.

```fish
##!/usr/bin/env fish

# open current clipboard as a buffer, apply given syntax, output file contents in clipboard on exit then delete file
# clim rust
# clim javascript
function clim
set tmpfile (mktemp)
wl-paste > $tmpfile

if test -n "$argv[1]"
nvim +"set ft=$argv[1]" $tmpfile
else
nvim $tmpfile
end

wl-copy < $tmpfile
trash $tmpfile
end
```

I end up copying scripts from all over the place and wanting to edit them, but I find it annoying to select in vim to overwrite my clipboard with the finished product. So, I use `clim` a lot. I was thinking of implementing additional logic to detect the language but I was getting issues with treesitter so I ended up not doing it.
>>
>>108500702
>>108500800
and yea it's more about it not deleting or reading files it shouldn't need to do the task.
>>
>>108499952
just use docker
>>
>>108500843
nta, but I don't want to fuck around with containers for running a one-off
>>
>>108479881
>ffmp
Thanks
>>
ffmpeg -f alsa -i default -f wav - | ssh your@server 'aplay -'
>>
>>108480572
>distroboc
why?
>>
Top secret exotica extravaganza:
> sudo -E ip netns exec vpn-ns runuser -u teto -- flatpak run org.qbittorrent.qBittorrent
> ^ Run qBittorrent flatpak inside of network namespace called vpn-ns
>>
>>108501303
Mustard gas alert



[Advertise on 4chan]

Delete Post: [File Only] Style:
[Disable Mobile View / Use Desktop Site]

[Enable Mobile View / Use Mobile Site]

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.