40
votes
Whats the most important alias or function in your bashrc file?
Hello new member here to Tildes!
I just wanted to see what all people are putting in their bashrc file that makes them more productive?
Hello new member here to Tildes!
I just wanted to see what all people are putting in their bashrc file that makes them more productive?
This one, by far:
If you run
l
on a file, it opens it inless
(I now use bat because I like the syntax highlighting, but honestly I might switch back at some point); if youl
a directory, it runsls
.It has several deficiencies, but it works well enough for me.
What are the deficiencies, it you don't mind me asking?
The fact that it doesn't handle multiple arguments at all is the biggest one – I try to use it with a glob fairly often, but it just acts upon the first argument.
Probably you'd just want to test if the number of arguments is greater than 1, and if so then just unconditionally call
ls
.Honestly, the one I probably use the most is
It saves so much typing, and now it's muscle memory. First thing I do on a new install.
Haha, I came here to post:
Hilarious! I wonder what other one-letter aliases there are. I have
v=$PAGER
as well, but I hardly ever use it. And to exit, I just Ctrl-D :)I have a few one-letter or very-abbreviated ones:
I have a lot of
sudo
aliases too, I actually use a loop for them:I think that's right; I'm at work right now so I'm not 100% sure if that's the way it's written.
Assuming you're not using Fish, you probably don't want the parens – that'll run
shutdown reboot pacman
in a subshell, which probably will just complain about the arguments, but if you're unlucky might shut down your computer.Oh no, I wanted it to be an array! I guess I can just list out the commands right, without parentheses?
Yep, that should work.
I do something very similar, with e=cd, o=ls, u=$EDITOR. I use a dvorak keyboard, so all of the home row vowels map to a common function.
Of course, I'm trying to use eshell more, so having all of these in my muscle memory is starting to be more trouble than anything else, as I've been too lazy to mirror them.
I was about to ask what the mnemonic was for you, but then I saw your "home row vowels;" neat!
and
fuck reruns the last command with sudo.
cls cleans the crap off my screen and gives me context for where I am. My brain for some reason can't handle having tons of stuff from previous commands, so clearing everything out is nice. It's kinda like turning down the radio when driving in bad weather.
If the only criteria is "more productive", then: (by a long shot)
(autojump)
Second place:
(history long enough to keep all my frequently used commands)
Third:
(highlights matches, with color, when grepping)
I would say no, for servers if there's anything repetitive it usually gets automated, so autojump wouldn't be useful.
For other people's computers I wouldn't know their paths anyway.
Dangerous one-letter aliases on the other hand...
Oh dang I didn't know about the
color
flag ongrep
. Thanks!I'll tag along. This allows me to share history between bash sessions/tabs/windows, helps to quickly
ctl+r
a thing I've just typed in a different window and just have more confidence in history lookup overall:v for (neo)vim.
same here.
Ah, I've been using zsh for so long I'd forgotten that .. being aliased to 'cd ..' wasn't the default.
I also alias a bunch of common directories I go to– my sync(dropbox alternative) folder, my work/official repos folder, etc.
As a fan of [Crystal][cr]:
And why don't people use syntax highlighting?
[cr]: https://crystal-lang.org
Fixed Happy? :)
My desktop's name is Chalupa, and it controls the lighting, so on my laptop I have an alias called Chalupa that SSHes in, sets up some environment variables, then executes whatever command. So
chalupa blinc black
to shut the lights off at night. Orchalupa ytplay "Benny Hill Theme"
to search youtube and play whatever.Please tell me your desktop's name is Enchilada
Close. Few similar letters, anyway. Laptop is Empanada.
Ahh, of course, of course. I don't have a creative bone in my body and simply refer to my devices by the final part in their private IP -- '7', '3', '8', etc
Just a few simple ones for me that I've added over time:
Getting IP addresses is obvious. The hash aliases were used when I was doing some CTF exercises and needed a way of generating some hashes quickly in the shell for a given set of words so it was nice to be able to pipe values into it. The dedup one was when I was working with a lot of manual data compilation from horrible, horrible, disparate sources for a client and I wanted a quick way of cleaning data I'd copy and pasted.
I forgot where i found this one but here it is
Not as convenient as a bash-only thing, but you might want to look at atool
My favorite is just
aunpack <any-kind-of-archive>
, which does what you posted but with some extra nice stuff.For example, if it's just an archive of files on the root level, it will create a folder first and dump them in there, instead of littering your current folder.
Seems cool will try it. Thank you
Another tool that does something similar is dtrx, which is available via the Ubuntu package manager which makes it really convenient for extracting lots of different things.
This is pretty neat actually.
May be off topic since you specified bashrc, but using zsh with the git plugin saves me tons of time. I often type
gst = git status
gl = git pull
gcmsg = git commit -m
gp = git push
so saves me lots of time for git stuff.
In my .zshrc I also have aliases to cd to common repos, I just type
cdv = cd V_repo
cdl = cd L_repo
where v and l are the first letters of some of my repos.
I'll cheat and post two:
Add all changes to tracked files to the previous commit and force push to
origin
.and
This will make your
PS1
look like:when you're in a git repo.
You might also be interested in this old thread :)
alias u="cd .."
Not really useful, but I just did the following to take a break from studying:
These go to the next or previous directory, alphabetically, under the same tree as
$PWD
. Gues-1
tohead
andtail
is a GNUism.Why are you setting
$OLDPWD
manually? Also, you can use${PWD%/*}
instead of$(dirname "$PWD")
and${OLDPWD##*/}
instead of$(basename "$OLDPWD")
. Also, quote your variables; you can also use double brackets instead of single ones so you won't have to quote the variable in the test. And why did you use an if statement instead of just&&
? You could actually probably replace that whole loop with afind
one-liner. Finally,head
/tail
's-<number>
is obsolete syntax and is discouraged.I know that you weren't too serious about writing this; just encouraging good form. :)
Thanks! I've tried learning those substitutions many times, but I keep forgetting them, and I'm not sure if they're in POSIX (I keep my bashrc and .profile mostly compatible with POSIX sh so that I don't need different files for different shells, a habit from when I used FreeBSD).
$OLDPWD
wasn't being set for some reason, that's why I set it manually. But I did a typo or something I guess.New aliases:
Note that the quoting around the command substitution doesn't apply to the commands inside; those quotes don't need to be escaped unless there's another reason I'm missing, and the variables should probably be quoted.
Thanks!
That's pretty handy, I'll copy that. Currently I open the folder and use a shortcut to open the Terminal in that folder
I do
etc for 5 or so levels
These ones:
OMG same 😂
I actually just uninstalled Void, but I might go back. Manjaro KDE is too fancy in some ways, and I'm missing the slimness of Void. Maybe if I reinstall it I'll put it together better ..
I just installed Void Linux and the
xbps-*
commands are too lengthy to type out every time...Somebody did create a wrapper for those commands: https://github.com/netzverweigerer/vpm. So instead of typing
xbps-*
you can just typevpm *
which IMO is more intuitive.I have this couple for job control:
With these I type
j
,f
,b
,f 1
andb 1
instead ofjobs
,fg
,bg
,fg %1
andbg %1
. These are one of the most frequented ones.I also have
alias sudo="sudo --preserve-env"
which is convenient. With this sudo uses my env.Lastly, these below are my Debian aliases which I use often:
Edit: replace pg with less, it is another alias I have for $PAGER. Sorry for the inconvenience.
What's
pg
? command-not-found doesn't seem to know about it.Whoops, sorry. It is an alias for
$PAGER
, you can replace it withless
ormore
.pg
itself is, where available, a historical pager used beforemore
. I don't know which package would have it tho, I think I encountered it on FreeBSD.I make extensive use of aliases, and after all my aliases are defined I have this:
Which spits all my aliases out for me when I start a new login shell or call the
aliases
function. Especially useful when I have just added a new alias and haven't committed it to memory yet.Example (restart docker-machine and bring up an arbitrary container tree from a compose file in my localdev directory, then return to whatever directory I was just in):
The alias gets syntax highlighted to cyan and multiple commands (ending in
;
or&&
stack although it's a very naive implementation.The function is not pretty and it doesn't scale well to very large aliases but I like it all the same.
This is on macos so there may be some adjustments needed for Linux, I am not sure.
Is there a way to have this only show aliases defined in your .rc file? I have a bunch from oh-my-zsh that I don't even use, so the list of arises is way longer than is practical to read through.
Didnt write it in
.bashrc
because I wanted to be able to invoke it in other scripts, but recently/usr/local/bin/send-to-vms
has been a big help in my experiments with virtualization:Been using it to update all my VMs at once, or to write a file to all of them. Im sure theres something dedicated to this in libvirt, but thats boring :D
Not really crucial, but it feels nice to have it.
I use couple aliases that setup my workflow.
Now, I just have to figure out how to execute commands as root on startup without the need to type my password. When I want to change brightness with i3, I register keyboard keys and run my script that writes directly into some random file, because there is no other way how to make it work. The problem is that the file is root read/write only, so I have to have another script which chmods the file so my brightness changing script can write into it. The problem is that I have to type my password again to run the chmod script, which is annoying.
Whereabouts is the file located? There's probably a better solution then chmodding it on every boot. e.g. if it's in /dev, then you can probably write a udev rule that will set the permissions up automatically.
It's
/sys/class/backlight/intel_backlight/brightness
. I thought about setting up cron to run at reboot and chmod the file, which should work, but I'm not sure I like the solution.I wonder why is root even needed to change this file, gnome can do it without root. I tried some packages that would allow me to change the brightness without messing with the file, but none worked.
Uh... it sounds like you're trying to change the permissions on the file at startup to be writable by the user. This isn't what you want to do. This is very not Linux-like. You should be setting up a script to be run as root on startup, which would allow the file modifications to run without having to perform a
chmod
.What distro are you running? Depending on which distro and which version, there should be a far more elegant solution to this problem that is well-supported and generally the officially recommended approach.
I use Ubuntu 18.10, so any kind of community support is more than unlikely.
Would you recommend me something to learn? I can probably find how to run script as root on startup, but I have no idea what should be done next.
Regarding running as root, consider taking a look at this thread. Specifically, I would recommend looking at this answer or this one. Please note that it's absolutely essential in the case of using a crontab to set it as root via
sudo crontab -e
, otherwise you will run into the same permissions issues.As for what to do from there, I honestly don't know. This is why I'm asking for details about your particular problem. I have only the vaguest idea of what it is you're trying to accomplish. I literally cannot help you any further without additional details, otherwise I'll just be sending you random resources to look at that may or may not even be relevant to actually solving your problem. In order to receive even a modicum of guidance, you'll first need to describe exactly what it is that you're trying to accomplish and how you're trying to accomplish it.
If you don't want a straight-up answer so you can figure it out on your own, then that's fine. But details are still needed to assess what would need to be done in the first place and whether or not you're on the right track so I can determine what direction to point you in.
Thank you. I don't really need some tutorial or step-by-step solution - it works for now, even with the annoying chmod step (which could be automated with the links you sent). And I think kiddico's solution might work, as it looks like he had the same problem.
So, the problem is: I want to set screen brightness. The usual tools (eg xbacklight) didn't work (but light from kiddico's comment might). So I found a way how to set it by writing to /sys file. But I have to be root to do it. So I'm now more interested in how is it done without root, how does gnome and other tools do it, so when I encounter simmilar problem, I'll be able to solve it, and especially know how did the solution work.
I searched and maybe making some udev rule should work? I'll try it as I get to my computer. As I understand it, udev rules should somehow manage devices, so it seems to make sence.
Sorry for the delay. I've been a bit busy.
Hitting
udev
would probably be the way to go, so you're likely on the right track. You might take a look at this Arch manual page regarding backlight configuration management. They even touch onintel_backlight
at some point, it looks like. Please note the following snippet:You'll have to modify it to hit
intel_backlight
instead, which might look something like this:You'll ultimately have to dig around a bit more to determine whether or not this is enough to suit your needs and, if not, which changes you'll need to make to get it working, but it should at least get you pretty close :)
Hey, I used to have tons of problems on my thinkpad with backlight controls and i3. I started using light. An update broke my original setup that just used xbacklight. I had to do what you're doing (and change a file's value) until someone pointed me towards (the) light. It's not horribly hard to setup, here's all I had to do to make the inc/dec brightness keys work. (after installing light that is)
When I was working full time, I had a fair amount of stuff in my zshrc, but it was mainly to speed up things like kubectl commands and pruning docker images. My PC has Windows on it (I want to install Linux Mint but I can't get KVM GPU passthrough working), so my WSL zshrc is pretty simple, these are the only aliases I have:
(I also have aliases for my university's HPC clusters, but those are just SSH.)
Edit: I almost forgot:
Oh, fuck. Rails. I'm going to go on a tangent for a moment and tell a little story about my own little hell.
During my own university studies, one of the required courses for my chosen "track" (a set of courses defining your specific focus, e.g. security or networking) was an introduction to software engineering principles. This was an upper-division course that focused on issues ranging from software development lifecycles, to project management, and in a later iteration of the course, even working on joint projects with teams from other countries (a story for another time). For this particular course, though, we focused mostly on doing a couple of "large" (by university project standards) software projects spanning multiple weeks in small teams.
Well, my team was... "special". They decided, for some unknown reason--possibly the sadistic whisperings of Satan himself influencing them--that we should all use a language, framework, and tech stack that none of us had any experience with whatsoever. That was Rails. None of us--not a single one of us--even knew what the hell the difference between a "GET" and a "POST" request was... and they decided we should use Rails. Super.
Oh, but here's the best part: I was the one who ended up blowing through the documentation, doing hours of research, and prototyping basic proof of concept implementations just so I could get the others on board with how Rails even worked. If I hadn't done that leg work, we probably would've still been stuck trying to figure out the most basic shit half way through the project timeline. We had to not only figure out how to work with Rails, but how to implement behavior that we'd never had to implement before in any project of any type. Things like geocoding, array serialization and de-serialization for storing in database columns, handling file uploads, and various other little pieces that would otherwise be pretty simple if literally any of us had ever worked with web development for anything more than basic JavaScript and DOM manipulation.
And since the guy who was in charge of deploying the app onto a server so we could actually demo it couldn't figure out how to get things working, we ended up running it from a cloud IDE... which had a tendency to crash randomly when we wanted to test a critical piece of functionality. Including during our end-of-term presentation. So the entire time it was seriously the blind leading the blind through a freakin' minefield and somehow, by the grace of some merciful deity, we were given a passing grade in the end.
It was truly a nightmare and I'm amazed that I never developed even a slight aversion to web development as a result.
Kind of a long tangent, but seeing those Rails aliases brought that little bit of academic trauma out of physical memory and right into my L1 cache.
Mine's simple!
My monitor setup demands a restart after a while - the 2017 Macbook Pro just doesn't agree with my hardware - so I tend to have a simple
startup
command that runsopen
with a few apps,bubu
that I believeoh-my-zsh
installs (that updates Homebrew fully) and then ends with opening a nice cleantmux
for me to begin my day.export HISTCONTROL=ignoreboth:erasedups
I often find myself, for example, running
make
over and over again, so if I don't have this set and want to go to a previous command it takes foreversetxkbmap -option ctrl:swapcaps
Caps lock is just such a useless key in such an important position on a keyboard.
As a recent windows user:
alias start=xdg-open
Not really aliases or functions, but the two for me are:
Both of these have been my secret sauce for flying in the shell.
Downloads the latest episode of the No Agenda podcast. Could be prettier, but a critical part of my Thursday and Sunday routine :)
I have some there are maybe more interesting or powerful, but these probably save me 1-5 days per year:
lr () { ssh mat@192.168.1.66 ${1+"$@"}; }
Nothing too special, if I do
lr
on it's own it connects to my home server. But if I do
lr full_backup.sh
It runs the command 'full_backup.sh' on my home server and then disconnects. Which is handy if I do just want to run one command remotely, which I quite often do. I have a bunch of two letter aliases for my most used remote machines.
which calls start.sh, which has some variation of
It's basically a hacky session manager I cobbled together based on an example from the Arch wiki (that used DISPLAY and XDG_VTNR), but I've been experimenting with other distros, and wanted a more generic solution that works for my single-monitor computers. It helps with the minor instability
nvidia
brings to my Arch desktop.