Share a script/alias you use a lot
A while ago I made a tiny function in my ~/.zshrc to download a video from the link in my clipboard. I use this nearly every day to share videos with people without forcing them to watch it on whatever site I found it. What's a script/alias that you use a lot?
# Download clipboard to tmp with yt-dlp
tmpv() {
cd /tmp/ && yt-dlp "$(wl-paste)"
}
204
Comments143
I often want to know the status code of a
curlrequest, but I don't want that extra information to mess with the response body that it prints to stdout.What to do?
Render an image instead, of course!
curlcattakes the same params ascurl, but it uses iTerm2'simgcattool to draw an "HTTP Cat" of the status code.It even sends the image to stderr instead of stdout, so you can still pipe
curlcattojqor something.LOVE this
this one is clean asl
I wrote a script called
please. You inputpleasefollowed by any other command (e.g.please git clone,please wget blahblah) and a robotic voice will say "affirmative," then the command will run, and when it completes, the robotic voice reads out the exit code (e.g. "completed successfully" or "failed with status 1" etc.)This is useful for when you have a command that takes a long time and you want to be alerted when it's finished. And it's a gentleman.
pleaseshare the script?It's full of random shit I put in as a joke, but here it is. You can use
please -sto get lightly roasted when your command fails.::: spoiler spoiler
:::
That's so neat
You can also use something like notifyd to generate a pop up for visual feedback :) I can't remember the exact command right now though. Differs per distro or desktop environment, obviously.
notify-send 'command finished!'works pretty wellAlso,
printf '\a'will output an alert bell character which should make the terminal beep/blink and be highlighted for attention by your wm/compositor if it's unfocused.I have that aliased to
ato get notified whenever a long running command finishes just by adding;aat the end.I once experimented with something similar, except it was supported to trigger my smart speaker and drop into another part of the house to tell me.
Honestly, I really need to replace my proprietary smart speaker system with something self-hosted; it’s just I only recently have had the time to start cinsidering.
Here are probably the most useful ones. I prefer for
rmto be interactive so I don't accidentally delete something important and formkdirto create a parent directory if necessary.This extract function (which I didn't make myself, I got it from when I was using nakeDeb) has been pretty useful too.
I have a similar docker/podman alias, except I pull first. This greatly reduces downtime between
downandup, which is nice for critical services.Yeah, that makes sense. I don't have anything critical; just nginx, a book server, a recipe collection, and some other small stuff.
alias clip='xclip -selection clipboard'When you pipe to this, for example
ls | clip, it will stick the output of the command ran into the clipboard without needing to manually copy the output.I use a KDE variant of this that uses klipper instead (whatever you pipe to this will be available in klipper):
` #!/bin/sh
Pretty sure this only works on x distros?
wl-copyandwl-pasteare for Wayland FYI.Yep, pretty sure you are right.
real ones watch the train of shame
alias sl='ls | while IFS= read -r line; do while IFS= read -r -n1 char; do if [[ -z "$char" ]]; then printf "\n"; else printf "%s" "$char"; sleep 0.05; fi; done <<< "$line"; done'I can't easily check if it works until I get home to my laptop, but you get the idea
That's a helpful one! I also add a function that creates a tmp directory, and cds to it which I frequently use to open a scratch space. I use it a lot for unpacking tar files, but for other stuff too.
(These are nushell functions)
Here's a script I use a lot that creates a temporary directory, cds you into it, then cleans up after you exit. Ctrl-D to exit, and it takes you back to the directory you were in before.
Similar to what another user shared replying to this comment but mine is in bash + does these extra stuff.
alias fuck='sudo $(history -p \!\!)'sudo !!Try it, and you will find it just does not provide the same emotional peace.
I like to imagine I'm yelling it. SUDO!!!
:D
Nice
Why not use thefuck which also corrects typos?
Because i'm not a psychopath, just autistic.
I have the same but it's called "please"
i touch computers since almost 40 years. "Please" stopped being an option somewhere in the early 2000's.
One of favorites cds to the root of a project directory from a subdirectory,
This tmux wrapper is remarkably convenient:
Usage:
Since 720p downloading isn't really available on yt-dlp anymore, I made an alias for it
alias qr='qrencode -t ansiutf8'This makes qr codes in the terminal.
needs the
qrencodepackageExample usage and output:
on most of my systems I get tired of constantly
lsing after acdso I combine them:(excuse if this doesn't work, I am writing this from memory)
I also wrote a function to access docker commands quicker on my Truenas system. If passed nothing, it enters the docker jailmaker system, else it passes the command to docker running inside the system.
I have a few similar shortcuts for programs inside jailmaker and long directories that I got sick of typing out.
I used this a lot when I had to deal with CSV files — it simply shows the data in a nice format. It's an alias for the fish shell by the way.
I have a few interesting ones.
Download a video:
Execute the previous command as root:
Delete all the Docker things. I do this surprisingly often:
This is a handy one for detecting a hard link
I run this one pretty much every day. Regardless of the distro I'm using, it Updates All The Things:
I maintain an aliases file in GitLab with all the stuff I have in my environment if anyone is curious.
Fun fact if you are using bash,
!!will evaluate to the previous command, so if you miss sudo on some long command, you can also just dosudo !!.With the added benefit of it looking like you're yelling at your prompt in order to get it to use sudo.
I usually set up an alias or script to update everything on my system. For example, on Ubuntu, I would do this:
alias sysup='snap refresh && apt update && apt upgrade'And on Arch, I do this:
alias sysup ='flatpak update && paru'Funny enough you'd need to use
sudoto run this on Ubuntu, but not in the Arch example because paru being neatHere is mine for EndeavourOS (based on Arch, BTW):
And related for uninstalling something:
Can I introduce you to Topgrade? ;)
Why install another bit of software when a simple alias will do the job nicely?
Because:
Of course if you're a minimalist, then you probably don't have that much stuff that needs upgrading in the first place. For me personally I have
deb-get,uv,cargo, andflatpak, to name a few; the alias was getting longer and longer until I was able to remove it completely by switching to Topgrade.For me, I find it handy because it catches a bunch of stuff I always forget, like updating Docker containers. Also if you have Am installed it'll even update your Appimages.
I consider updating my docker containers part of updating my dev environment, which is on a different schedule to my system updates. I use a function for updating them.
I use Topgrade, but I use the alias
updateto run it lolI have a similar update function here. With a bit more bells and whistles: https://github.com/dannyfritz/dotfiles/blob/e53d410364bf6e2f4e1de4b9c6abbbc832db67b1/fish/config.fish#L123
I have something similar.
I did have code that would generate these automatically but Idk where it is.
alias gimme='git checkout'Twins(-ish)!
it's somewhat vibe coded but the one i probably use the most is this one to swap between speakers and headset. the device name to look for is just put directly in there, it'd take some adjustment to run it on different machines. this is in my .bashrc:
generally i try not to use too many custom things because for work i regularly work on all kinds of different servers and i've just been too lazy to set up some solution to keep it all in sync. someday....
I have a collection of about 8 machines around the house (a lot of Raspberry Pi) that I ssh around to from various points.
I have setup scripts named: ssp1 ssp2 ssba ss2p etc. to ssh into the various machines, and of course shared public ssh keys among them to skip the password prompt. So, yes, once you are "in" one machine in my network, if you know this, you are "in" all of them, but... it's bloody convenient.
I used to have scripts like that, but eventually switched to ssh aliases. You can set up an alias for each machine in
~/.ssh/configwith lines like this:Then access with
ssh p1. Slightly more typing, but avoids adding more commands to your $PATH. Also has the benefit of letting you use the same alias with other ssh-related commands like sftp.jmpd(jump directory): fuzzy finds and opens directory with fzf
also a couple to easily power on/off my 4g modem
I'll share 3:
i also have the chmod one, but mine is named just x:
I also have the
yt-dlp "$(wl-paste)"one, but its build around a custom script. So sharing it here makes no sense. Its funny how often we do same thing in different ways (extracting or creating archives in example). Often aliases get development into function and then they turn into scripts. For some of the more simple aliases, here a selection:I have a bunch of the server aliases. I use those and gl the most.
Whatcha get in that log
Hahaha. Fucking autocorrect. Git log.
You can also use ssh shorthands in ~/.ssh/config
I do have the servers in
~/.ssh/config. I just got tired of typingssh serverand wanted the be able to just typeserverto ssh in.We almost have the same setup then, I use
in my .bash_aliases to parse the ~/.ssh/config file and cut off the 'ssh ' part automatically for every Host I have in there.
That is a lovely setup. I'm gonna drop that into my
bash_aliasesso much more elegant than me adding the alias for each server.I've only used aliases twice so far. The first was to replace yt-dlp with a newer version because the version that comes pre-installed in Linux Mint is too outdated to download videos from YouTube. The second was because I needed something called "Nuget". I don't remember exactly what Nuget is but I think it was a dependency for some application I tried several months ago.
Nuget is a the .NET package manager. Like npm or pip, but for .NET projects.
If you needed it for a published application that strikes me as fairly strange.
I looked through my bash history and it looks like I needed it to build an Xbox eeprom editor for Xemu. Xemu doesn't (or at least didn't, I haven't used newer versions yet) have a built in eeprom editor and editing the Xbox eeprom is required for enabling both wide screen and higher resolutions for the games that support them natively.
I just looked at Xemu's documentation, and it looks like they've added a link to an online eeprom editor, so the editor I used (which they do still link to) is no longer required.
Ah, if you need to build a .NET project that makes sense
For the newer version of program, that's why we have the $PATH. You put your program into one of the directories that is in your $PATH variable, then you can access your script or program from any of these like a regular program. Check the directories with
echo "$PATH" | tr ':' '\n'My custom scripts and programs directory is "~/.local/bin", but it has to be in the $PATH variable too. Every program and script i put there can be run like any other program. You don't even need an alias for this specific program in example.
Well, my full
functions.shwon't fit in a comment, so here's 2 of my more unique functions that makes life a little easier when contributing to busy OSS projects:I made this one to find binaries in NixOs and other systems
Then I made this one to, if I have a shell o opened inside neovim it will tell the neovim process running the shell to open a file on it, instead of starting a new process
Lastly this bit: which if it detects a file and a line number split by a
:it will open the file and jump to the lineall of my bash config is here
On MacOS, to open the current directory in Finder:
alias f='open -a Finder .'I use Clevis to auto-unlock my encrypted root partition with my TPM; this means when my boot partition is updated (E.G a kernel update), I have to update the PCR register values in my TPM. I do it with my little script
/usr/bin/update_pcr:I run it with sudo and this handles it for me. The only issue is I can't regenerate the binding immediately after the update; I have to reboot, manually enter my password to decrypt the drive, and then do it.
Now, if I were really fancy and could get it to correctly update the TPM binding immediately after the update, I would have something like an apt package shim with a hook that does it seamlessly. Honestly, I'm surprised that distributions haven't developed robust support for this; the technology is clearly available (I'm using it), but no one seems to have made a user-friendly way for the common user to have TPM encryption in the installer.
Is clevis using an attestation server or is it all on a single machine? I’m interested in getting this set up but the noted lack of batteries included for this in the common distros makes it a somewhat tall order.
In my case, no; it’s all a single machine - it is in the initramfs and uses the system’s TPM to (relatively) securely store the keys.
It can be set up with an attestation server, but you certainly don’t have to do it. The Arch wiki has a really good article on getting it set up.
How difficult is it for an adversary to get in the middle of the TPM releasing the keys to LUKS? That’s why I would want attestation of some sort, but that makes it more complicated and thinking about how that would work in practice makes my head spin…
Vulnerabilities certainly do exist, but I’m pretty sure the attacker has to be well-equipped
I’d call it a protection against data getting cracked in a petty theft, but if your attack vector is much more than that, there are other measures you should probably take. I think Clevis also works with Yubikeys and similar, meaning the system won’t decrypt without it plugged in.
Heck, I think I know someone who just keeps their boot partition with the keys on it on a flash drive and hide it on their person.
Hey OP, consider using $XDG_RUNTIME_DIR instead of /tmp. It's now the more proper place for these kinds of things to avoid permission issues, although I'm sure you're on a single user system like most people. I have clipboard actions set to download with yt-dlp :)
My favorite aliases are:
alias dff='findmnt -D -t nosquashfs,notmpfs,nodevtmpfs,nofuse.portal,nocifs,nofuse.kio-fuse'alias lt='ls -t | less'Good idea! I'll steal that but I would rather be able to give a directory path as parameter (and show in colors, and don't pause if less than 1 page of content, and support the scrolwheel), also piping
lsforces it to be 1 single column so might as well show more details, personally I'm gonna use this instead:Thanks for sharing! My ls is already aliased to ls -h --color=auto
i use
to display images in my terminal pretty simple but nice
I have that one too, but my alias is called icat
To answer your question realistic I did
history | sed "s/.* //" | sort | uniq -c | sort -nwhich returned as first non standard command
lrwhich from mygrep lr ~/.bashrcisalias lr="ls -lrth"A few days ago I posted a one-liner to do the same thing too. It will resolve aliases from your history and expand program paths to its fullpath. I thought you might be interested: https://beehaw.org/post/20584479
Thanks for sharing, always nice to learn alternative ways to do so!
alias ed=$EDITORExtremely convenient on a qwerty keyboard.
This should probably be a default nowadays. Does even a single person here use the real
ed?Me. Along with vi depending on my mood.
I alias traditional stuff to better, usually drop-in versions of that thing on computers that have the better thing. I often forget which systems have the better thing, so this helps me get the better experience if I was able to install it at some point. For example I alias cat to bat, or top to htop, or dig to drill, etc.
alias ed=$EDITORis my most used alias by far.For docker: I’m not following best practices. I have a giant docker compose file for my entire home lab, this is how I update things:
Polls for potential zombie processes:
I've stolen a bunch of Git aliases from somewhere (I don't remember where), here are the ones I ended up using the most:
I also often use
And finally some Nix things:
This makes me want spacemacs for the terminal
I have started my daily drawing journey which i still am bad at it. To create a new .kra files files every day I use this
Monika from ddlc? :O
JUST MONIKA
Best waifu of history <3
My desktop text editor has an autosave feature, but it only works after you've manually saved the file. All I wanted is something like the notes app on my phone, where I can jot down random thoughts without worrying about naming a new file. So here's the script behind my text editor shortcut, which creates a new text file in ~/.drafts, names it with the current date, adds a suffix if the file already exists, and finally opens the editor:
Ooooou I got a couple :3
This one is just a basic mirror fixing thing cuz sometimes I go a while without updating pacman:
This function I made to create virtual audio sinks so I can route audios via qpw and play earrape into discord calls if I want XD
Simple parser function I made that makes a whole repo using my git key so it's not just locally created I kinda forgot why I made it tbh:
Awesome mpv function I made that allows for real time pitch+speed shifting via hotkeys and is flexible with extra parameters and shit:
Automatic audio router for firefox audio streams that uses the aforementioned create_sink function to make a specific sink that I can use carla on to mix and make cool shit out of haha
This lets you run
git cdto go to the root of your repo, orgit cd foo/barto go to a path relative to that root. You can't do it as an alias because it's conditional, and you can't do it as agit-cdcommand because that wouldn't affect the current shell.alias cls=clearMy first language was QB, so it makes me chuckle.
Also,
alias cim=vim. If I had a penny...I also have cls aliased to clear! I used to use windows terminal and found myself compulsively typing cls when I moved to linux.
alias nmtui="NEWT_COLORS='root=black,black;window=black,black;border=white,black;listbox=white,black;label=blue,black;checkbox=red,black;title=green,black;button=white,red;actsellistbox=white,red;actlistbox=white,gray;compactbutton=white,gray;actcheckbox=white,blue;entry=lightgray,black;textbox=blue,black' nmtui"It's
nmtuibut pretty!None, I like to type
I PAID MONEY FOR THIS KEYBOARD AND GOD DAMN I AM GOING TO TYPE ON IT
alias scr=screen -dRUI don't know why Screen has any other flags. I do not want to bother learning the keyboard shortcuts for tmux even though its probably works better
To save videos from certain streaming sites that are not supported by yt-dlp, I catch the M3U playlist used by the page and with that I use this script that gets ffmpeg to put together the pieces into a single file.
I wrote this suite of scripts a few years ago and still use them to:
cfg/cfg.shif it's the first time using the toolsetup.shto configure the environment into a familiar/productive stateThe tools are flexible on hardware (more directed toward x64 systems at this time), and I (almost) never have to worry about OS upgrades. Just boot into a newer live OS image once it's ready. They are still a work-in-progress and still have a few customizations that I should abstract for more general use, but it's FOSS in case anyone has merge requests, issues, suggestions, etc.
Not exactly a single script, but I use scm breeze for git stuff. Has a ton of QoL features for working with git
https://github.com/scmbreeze/scm_breeze
For me it's pretty basic. It's mostly aliases for nix related commands, like rebuild-switch, updating, garbage collecting, because those nix commands are pretty lenghty, especially with having to point to your flake and everything. I'm thinking of maybe adding an alias for cyanrip (cli cd ripper), because i recently ripped my entire cd collection, but going forward if i buy another cd every now and then, i'll probably end up forgetting about which flags i used.
Currently using this to resize screenshots in a Word doc
#Requires AutoHotkey v2.0
^+1:: { Send "{RButton}z{Tab 3}4{Enter}" }
Is this just meant to make git clone always clone recursively?
Can't you do this with aliases in your .gitconfig?
yes it is. idk😄 i have a similar one for github-cli
I don't have anything too fancy. I use [theFuck(https://github.com/nvbn/thefuck) to handle typos, and I have some variables set to common directories that I use.
Technically not an alias, because I just use nushell's history + autocompletion everytime I use it, but one could alias it. I think I might even write a custom command for it, with
pathargument, some day. Anyway, here it goes:rsync -aPh -e "ssh -p 2222" [email protected]:/storage/emulated/0/PicturesArchive/ ~/PicturesArchive/I run an ssh daemon on my phone, and use this snippet to back up my photos.
I replaced rm with trash-put, just in case I realize I need some files that I removed down the line.
Official author don't recommend it due to different semantics. But honestly for my own personal use case its fine for me.
Also I like to alias xclip:
I don't recommend that either. If you get used to that 'rm' doesn't actually remove files and then your alias is missing for whatever reason it'll bite you in the rear at some point. And obviously the same hazard goes with a ton of other commands too.
Agree, comes down to risk acceptance honestly.
I accepted the risk that comes with it. Same with some other aliases on equally hazardous commands.
Little tip: In case you need to use
rmdirectly, even with the alias in effect, you can put a backslah in front of the command to use its original meaning:\rm filenameoooh so does that apply to any command/user binary on the system?
I'm not sure what you mean with the question. If you have any alias like
alias rm='ls -l'in your .bashrc in example, then you cannot use the original commandrmanymore, as it is aliased to something else. I'm speaking about the terminal, when you enter the command. However, if you put a backslash in front of it like\rmin the terminal, then the alias for it is ignored and the original command is executed instead.Edit: Made a more clear alias example.
Oh ty ty that answers my question! I am fairly new to being a poweruser on linux so I may have worded that wrong XD
ganis:git add -A && sudo nixos-rebuild switch --impure -j$(nproc)Everyone who uses nixos probably has a similar alias set x)
g-pushBecause using docker can sometimes cause ownership issues if not properly configured in your docker-compose.yml, I just added an alias to ~/.zshrc to rectify that.
-edit- Only run this script in your user owned directories, e.g. anything from ~/ (or /home/<your_username>) you might otherwise cause ownership issues for your system.
I have a few:
3 scripts that are just docker compose up/down/pull, as scripts (remind me in 6 hours and I will post the scripts) so that it will CD to my compose folder, execute the command (with option for naming specific containers or blank for all) and then CD back to the directory I started in.
Similar to yours OP I copy many URLs and then run my script that takes the number of URLs I copied eg 5,and downloads them with
yt-dlpand GNUparallelto~/VideosI use CopyQ to hold the clipboard history.
Ooooh tmpv is a smart name for your little tool. I may steal it lol
Please do!
Not on mine tho
With how many new Linux users we get recently, I don't like this joke at all without a disclaimer. Yes yes, its your own fault if you execute commands without knowing what it does. But that should not punish someone by deleting every important personal file on the system.
In case any reader don't know,
rmis a command to delete files and with the optionrm -reverything recursively will be searched and deleted on the filesystem. Option-f(here bundled together as-rf) will never prompt for any non existing file. The/here means start from the root directory of you system, which in combination with the recursive option will search down everything, home folder included, and find every file. Normally this is protected todo, but the extra option--no-preserve-rootmakes sure this command is run with the root/path.Haha I know its funny. Until someone loses data. Jokes like these are harmful in my opinion.
I agree. This thread is for actual advice.
rm -rf /belongs in a joke thread.So, as a beginner, you would know how to make an alias but not the most famous Linux joke ever ? Explain your mental gymnastics.
Gonna run right out and try this on all the servers! Thanks!