5 ms·
Probably an unpopular opinion, but I find aliases and extensive dotfiles counterproductive. It's better to learn and remember the exact commands. If you find y
by _Marak_ 9y ago
Probably an unpopular opinion, but I find aliases and extensive dotfiles counterproductive.
It's better to learn and remember the exact commands. If you find yourself typing the same long command over and over again, the task should probably be automated or scripted as part of a separate pipeline.
Assuming you are successful with aliasing and don't accidentally do something unexpected and catastrophic to your system, the moment you login to another system you will be lost and unable to remember any of the original and core commands.
- stochastic_monk 9y agoThere are plenty of cases where it can be unproductive, but I find it very helpful in some cases. I find `alias gcr="git clone --recursive"` to be very productive for me. I never forget what it stands for, it saves me time, and I never have to go fetch all submodules if the repo uses them. `alias lt=ls -tor` is helpful, as it shows me extra information about files in reverse sorted order, so that the most recently modified files are at the bottom. I don't run any risk of forgetting either of these because of their mnemonic nature, and they're not something I can script.
- aynsof 9y agoI was of the same opinion as the GP until I started using Terraform. Coming from a sysadmin background, I was always told to use default tools 'because one day you'll ssh into a random server and it won't have any of your fancy tools and config'. So I started using Terraform. A lot. Day in, day out, I would type terrafrom, teraform, terrafomr. And I'm a good typist! But something about that word just makes it hard to get out right. (I have a similar issue with 'infrastructure'.) Finally replacing it with a 'tf' alias saved me a lot of frustration.
- outworlder 9y agoThis is actually supporting GP's argument. Why do you have to "type" terraform? Are you running terraform from your own machine? Don't. Setup a Jenkins pipeline or what have you. Unless you happen to work alone – and I'd argue even then. Moving Terraform to Jenkins was the second best thing we have ever done – first thing was moving tfstate to remote storage. You can provide any required parameters (or jenkins can fetch for you), run terraform init, plan, ask for confirmation, apply (and even perform retries). And then run any post steps. Even managers can use terraform now (and we have a pretty complicated setup). I guess only Terraform Enterprise might beat this, but I have little experience with that.
- yebyen 9y agoThis is a great way to go, but I think you're actually asking GP to have his cart before his horse. This is how I learned and how you learned, I'd guess... by typing the command into a terminal. Am I being luddite? I had to be dragged kicking and screaming to set up CI for my product's tests, but I see the value of it now. How many thousands of times should you type "terraform" in full before you're comfortable with all of the nuances of syntax and command-line arguments? (Or kubectl --namespace=kube-system get pods, or git pull --rebase origin master for that matter) And if these managers who couldn't use Terraform before, can use it now, but also require someone to set up a Jenkins job for them... I'd just be sorta worried that they might get the idea this tool could only be run with adult (Root-type) supervision, because I've seen it happen like this so many times. (I'm sure it's better than the alternative, which is a world in which managers can't or won't ever learn to run this tool at all, simply because it requires use of a command-line.) Just curious do you use Terragrunt or something like it? Or does the fact that Jenkins only allows a single job to run once concurrently actually obviate the need for that... I'm not using Terraform (but wish I was) although I've got a basic Jenkins setup for some CI things on my less than 10-person product team. To be fair I think you may have just convinced me that I need to be able to do this too. I actually have a Jenkins server and we use it for CI to run our product's test suite by hand, but not much else. We have a team that provisions EC2 resources, we have a team that handles security rules, and everyone is a competent professional but sometimes as a developer the appearance from the outside of that group is that a left hand does not know what the right hand is doing. I guess with Jenkins and a remote tfstate, you make it very easy to know who owns what resources, and to see who has done what, or even specifically which locks are actually open and what resource is currently in motion.
- aynsof 9y agoWe ran Terraform in Bitbucket Pipelines builds - full testing with awspec, remote state in S3, statefile locking in DynamoDB. It might surprise you, but there are cases where you might not want to run Terraform in a pipeline.
- yebyen 9y agoWhat is this awspec? I would like to subscribe to your blog or mailing list! :+100:
- shampster 9y agoI've got only 2 shortcuts I use all the time. 'r' = rsync -vrlHpogDtSx --numeric-ids --progress And a small python script '2' that allows me to ssh into any system within 4-6 keystrokes (even doing tty tricks to not require <enter>).
- racer-v 9y agoWhy do you think it's good to put a long command in a script, but bad to make it an alias? It sounds like you think shell dotfiles can't be managed across machines just like script files.
- _Marak_ 9y agoThat isn't exactly what I wrote, but I'll still try to answer your question. An alias is only going to be available to the current shell and it's going to be stored in memory. A script is going to be accessible to the entire system and stored on disk. In the majority of my use-cases I require shipping software to production systems and my scripts are used to manage production services. The last thing I want to do is having to manage aliases on multiple systems ( some of which I do not own ).
- racer-v 9y agoTo me the difference between a script and an alias is too trivial to quibble over. I'm fine putting all of my aliases into one-line scripts, if that would really make them easier to manage across systems. My basic philosophical disagreement is with the idea of avoiding interactive command shortcuts. This essentially limits you to only using command line features you can memorize, or be willing to look them up every single time. There are too many commands, with totally inconsistent argument styles, for this to be practical. The result is that you're only going to use a small subset of the command line's power if you limit yourself in this way. RANT: Yes, I agree alias ll="ls -l" is a crutch. But why does 'sort' use -t for separator and -f for field, while 'cut' uses -d and -k? The famously composable Unix tools really aren't very consistent. Radically improved tab completion and documentation (vs man pages and Info) might be a start, but in the end you have to evolve new syntax.
- cakes 9y agoPersonally - I write aliases locally that I know I don't need/can live without remotely (e.g. "vi" aliases to "vim" because sometimes I fail to get that "m" on there and I want vim but only on my laptop), I can't imagine writing "system-wide" things as an alias without losing some sleep. I'd agree with the concept of memorizing it in theory but I'm with you that it becomes a bit too much when the tooling differences in switches from command to command can be even minimally different (something as simple as scp "-P" vs ssh "-p" is easy to forget in the moment). Yeah, I can memorize that example but everything has flags for everything and they can be vastly different (like you mentioned sort vs. cut)
- dorfsmay 9y agoI agree to a certain extent. Definitely aliases. But, for your main tools, if dot files can make a difference then you should make an exception. Vim without my .vimrc is almost a different apps, and I'm way less efficient without it!
- _Marak_ 9y agoI agree that certain dotfiles can be fairly useful. I'm not using Vim, but I do keep configuration files for my local text editor.
- eikenberry 9y agoI'm not sure I see the difference between having your text editor configured vs. having your shell configured. My shell is my primary interface to my computer and I spend at least as much time interacting with it as I do my text editor. I just don't see the advantage of leaving it un-configured. You must jump systems much more often than I do.
- rasjani 9y agoThats why I write my code without any libraries or frameworks. Sarcasm aside, you are correct but it’s better to learn things first. But after a while, those aliases and dotfiles are just shortcuts. I’ve had my dotfile repo with things I need for something like 8 years and hasn’t changed much beside vim plug-in updates and I could just whip up the same setup manually but it would take a half a day to get everything to how I prefer things. They just save time and sanity.
- golergka 9y agoYour principle holds: it's always better, when exploring a new field, to start without try the most minimal libraries and frameworks after you already experience the pain they solve.
- derekp7 9y agoThis is actually one of the primary reasons I haven't gotten into Emacs. To get the most out of it requires customization to its startup config. But I spend most of my time on random servers I support, which won't have my custom configs on it. Now what would be really nice is to have config forwarding built into ssh, similar to how ssh key agent forwarding works.
- cup-of-tea 9y agoI do maintain some level of vim knowledge for when I'm on strange systems. But it's not hard to install my emacs config so if I'm going to spend significant time on a system I will do that. But if you can ssh in, you could just tramp on your local emacs to edit files remotely. It's quite magical.
- derekp7 9y agoIn my case, I have to support a large number (500 or so) Linux boxes that are hosted at customer sites (for a custom middleware-type application). And the remote access they have provided for us isn't a direct ssh connection, it goes through a web based gateway using an old active-x control, and embedded shockwave/flash based app (yes, yuck). I'm in the process of replacing that now.
- cup-of-tea 9y agoHow does infrastructure like that ever happen? Reading that made me feel slightly ill.
- lallysingh 9y agoI just use tramp to edit files remotely in emacs. Works reasonable well.
- cup-of-tea 9y agoWhat's with all the top level comments talking about aliases? Are you commenting on sl or actually replying to other comments?
- codetrotter 9y agoCounterpoint: My git workflow. I commit often and I commit a lot. For this there are a few but quite long commands that I use over and over and over again. I turned all of them into two-letter aliases. It’s perfect! Here is a direct link to the line in question of my bashrc: https://github.com/ctsrc/dotfiles/blob/a2c87d22a4de7486dadfe16f62505ee4cef0848e/src/bashrc/common#L49 https://github.com/ctsrc/dotfiles/blob/a2c87d22a4de7486dadfe... I recently put my dotfiles on GitHub. As you can see from the above linked file, my bashrc is short and sweet. Thes dotfiles were, counter to what one might think given how few and short they are, not thrown together in short time. These dotfiles reflect the specific workflow I’ve developed for myself over years of using FreeBSD, Linux and another couple of Unices. In the beginning my dotfiles were long and messy and they accumulated a lot of cruft that I never used. That’s why I didn’t use to have them on GitHub. But over time I cut them down to only the things I actually used. The end result was that my entire bashrc is authored by myself for myself with nothing copy-pasted from the Internet. That’s the secret to successful aliases as well IMO — make aliases where it really matters. Then you’ll only have a few, which in turn makes it easy to navigate systems where you don’t have your full set of dotfiles. My git aliases are very important to me, but since there are only a handful of them and I almost don’t alias anything else, I can easily type them onto new systems by hand if need be.
- AlexCoventry 9y agoMy aliases and dotfiles are a cheap form of documentation.
- ubernostrum 9y agoI find aliases and extensive dotfiles counterproductive. The first thing I do on a new machine is tweak my profile to alias 'cp', 'mv' and 'rm' to prompt me before performing destructive operations, and to be verbose about what they're doing. Doing this has saved me from myself several times. While I'm there I usually also set 'ls' to use colored output, since I like to have an easy at-a-glance way to know what it's showing me. The second thing I do is tweak the prompt to include the current time, so I can scroll back and find out when I did things, or see how long things took without having to use explicit timing commands. Doing this has also been helpful on multiple occasions. After that I go set EDITOR, set HISTCONTROL how I want it, and usually set up a couple other files which get sourced by the main profile, in order to set up tool- or API-specific env stuff. This does end up producing a fair bit of stuff in those "dotfiles" you dislike, but I find it to be a quite useful approach.
- outworlder 9y agoI agree that it can be an anti-pattern. However there is stuff like this: alias ec2ls='aws ec2 describe-instances --query '\''Reservations[].Instances[].[Tags[?Key==`Name`].Value|[0],State.Name,InstanceId,PrivateIpAddress,PublicIpAddress]'\'' --output text | column -t | sort' I could try to remember it and type every time. But why? Sometimes all I want to do is list instances and grep for something quickly. If I can 'ls' for files, why would 'ls' for AWS (or openstack or what have you) be any different?
- gregman1 9y agoAbsolutely this!