News for hackers. Stuff that matters.
Re:When I Stopped Trying to Self-Optimize, I Got Better by pdmccormick on Monday September 25, 2023 @09:28PM (#37653177)
Over the past year, I’ve made a deliberate effort to improve my “personal computing”, which for me is about how I use the shell. I start by trying to notice when I’m doing the same task multiple times and getting tripped up on the specific syntax or sequence of commands (i.e. what’s the Git command again to split certain files out of a previous commit into a separate one?) I will then create an alias, a shell script or maybe a larger program to start addressing it, solving my initial use case first, and gradually revisiting things over time to make improvements.

Through this process I’ve created a whole idiom of commands for myself. I have no pretense that they would be useful to anyone else, and I don’t sweat them beyond their ability to make my life easier. From these incremental efforts, I find I have access to a new kind of language in my mind. Especially with Git, I find myself seeing it as an extension of my mental process, integral to how I even think about solving problems, not just a VCS I use to push code around.

By noticing how I was working, I didn’t seek to optimize where I was at, I sought to graduate to levels where what previously needed optimization just doesn’t exist.

Re:When I Stopped Trying to Self-Optimize, I Got Better by adasdasdas on Monday September 25, 2023 @11:00PM (#37653790)
I thought everyone does this haha
Re:When I Stopped Trying to Self-Optimize, I Got Better by keyle on Monday September 25, 2023 @11:08PM (#37653838)
Everyone does this. Otherwise you'd go bat sh*t crazy trying to remember every intricate details of common tools.

also using ctrl+r and filter through older commands (ctrl+r to cycle) is also necessary for good mental health.

for example

    alias ll="lsd --icon never -l"
    alias lla="lsd --icon never -l -a" # all
    alias llr="lsd --icon never -l -r -a" # reversed
    alias lls="lsd --icon never -l -r -a -S" #by size
    alias llt="lsd --icon never -l --tree" #tree
    alias lld="lsd --icon never -l -d -a --tree" #directories tree

    alias m='micro'
    alias ss="git status"
    alias diff="git diff --color | cat"
    alias log="git log --graph --pretty=oneline --abbrev-commit"
    alias lz="lazygit"
    alias dc="docker-compose"

    # rust
    alias cr='RUST_BACKTRACE=1 cargo run'
    alias clippy='cargo clippy'
    ... many others
Soon enough, when you start piping these, you end up with your own bash language, cca. of that time you thought it was a good idea to augment C with macros (sic!)
Re:When I Stopped Trying to Self-Optimize, I Got Better by Izkata on Monday September 25, 2023 @11:41PM (#37654028)
I actually find it easier to memorize the flags than to memorize the commands I created myself, because they're a lot more descriptive than short commands like in your examples.

The few times I do come up with my own stuff, it's a 2+ line function (or full shell script) that can't be duplicated in a single command and can't be done as an alias.

Re:When I Stopped Trying to Self-Optimize, I Got Better by appplication on Tuesday September 26, 2023 @12:46AM (#37654501)
The problem is some stuff I just don’t do often enough to remember. Like clean up my old git branches.
Re:When I Stopped Trying to Self-Optimize, I Got Better by dehrmann on Tuesday September 26, 2023 @01:15AM (#37654739)
I memorize the flags because it means I'm comfortable on any machine. Issue in production, and your aliases aren't there? No problem.
Re:When I Stopped Trying to Self-Optimize, I Got Better by pdmccormick on Tuesday September 26, 2023 @01:50AM (#37654959)
I'm curious, how much time would you say you spend on a set of personal machines, versus connecting to random hosts?

My conceptualization of "personal computing" is something more akin to a home or a garden. It's a place where I should feel comfortable and relaxed. Familiar. It's a refuge of sorts, a place where I will inevitably spend an inordinate amount of time, and actually have a lot of real life experiences reflected (through the form of personal writing). Whether working, reading or writing, I tend to think of these machine contexts really as extensions of and foils for my mind. A discoverable mind palace, if you will.

Re:When I Stopped Trying to Self-Optimize, I Got Better by bayindirh on Tuesday September 26, 2023 @04:48AM (#37656326)
I'm not the OP, but I'm on the same boat with the OP.

For me it's 50/50. The good thing is, when you memorize the commands, and not customize your "base stations" extensively, the difference melts away.

My brain works in "contexts". I remember my native keyboard layout and US one, and I operate in one of these contexts. Same for the spoken/written language. When I switch completely, the mental load disappears, however it's not completely free in terms of brainpower.

So, removing a context is highly beneficial. When I connect to a remote system, I don't care about the commands, aliases, even the place I'm in. Look to the hostname, remember the task I need to do and let my brain loose on the subject.

There are no roadblocks, errors or anything to think about while working. As a result the whole fleet is my home base. I change machines like I change directories. Completely effortless, invisible in fact.

Also, extensive aliasing is limiting. When I know the flags to a command, I can compose and flex on the fly, which I do a lot, as the circumstances and needs arise.

Re:When I Stopped Trying to Self-Optimize, I Got Better by coldtea on Tuesday September 26, 2023 @06:29AM (#37657202)
One could see it as the opposite:

Forcing yourself to memorize flags, means you're just equally uncomfortable on any machine: that is, you haven't optimized any particular machine, especially the 1-2-3 machines you use 90% of the time with your aliases.

Not to mention in 2023 on doesn't have to memorize anything to have aliases on "any machine". Have your aliases on a file (or GitHub) and just download it and source it to whether you are.

Re:When I Stopped Trying to Self-Optimize, I Got Better by heavenlyblue on Tuesday September 26, 2023 @07:03AM (#37657488)
Optimising the addition of a few flags to a command is alin to optimising the length of variable names. I find that typing out flags gives me plenty of time to think about what I am doing anyway.
Re:When I Stopped Trying to Self-Optimize, I Got Better by coldtea on Tuesday September 26, 2023 @07:41AM (#37657828)
Yes, nothing says productivity like spending half and hour to find the right flags every time you need to use something outside the most common unix userland...

or getting them subtly wrong in some production shell script...

Re:When I Stopped Trying to Self-Optimize, I Got Better by heavenlyblue on Wednesday September 27, 2023 @05:13AM (#37672144)
So what you're saying that you're putting your own home-grown script wrappers from local machine to production deployment scripts?
Re:When I Stopped Trying to Self-Optimize, I Got Better by Zambyte on Tuesday September 26, 2023 @07:40AM (#37657824)
Eshell in Emacs let's you use TRAMP to access remote systems as simply as cd'ing to the remote directory. By doing that, you have all of the features of your local shell to work on the remote system.
Re:When I Stopped Trying to Self-Optimize, I Got Better by bionhoward on Tuesday September 26, 2023 @08:15AM (#37658144)
Awww, you can put the aliases inside your script and source it, then you can keep the aliases in prod!

You could even have your script automatically add the line to source itself to the profile, so you source it once and then it happens automatically!

Re:When I Stopped Trying to Self-Optimize, I Got Better by runjake on Tuesday September 26, 2023 @01:23AM (#37654786)

  alias lsa=“grep ^alias $HOME/.zshrc | sort”
Re:When I Stopped Trying to Self-Optimize, I Got Better by supriyo-biswas on Tuesday September 26, 2023 @04:56AM (#37656389)
Just the “alias” command will list all your aliases, there’s no need to define a separate alias apart from convenience.
Re:When I Stopped Trying to Self-Optimize, I Got Better by ph4evers on Tuesday September 26, 2023 @04:05AM (#37655996)
Except for tar. But there I use the mnemonic “xtrackt ze files”
Re:When I Stopped Trying to Self-Optimize, I Got Better by contravariant on Tuesday September 26, 2023 @05:26AM (#37656641)
That may work, but I can never for the life of me remember what on earth each flag was for.

Doesn't help that '-a' basically means 'all the flags', meaning you have to know them all to figure out what on earth it's doing. Or just hope it is enough.

Re:When I Stopped Trying to Self-Optimize, I Got Better by 3np on Tuesday September 26, 2023 @07:27AM (#37657695)
Neat. Now do rsync.
Re:When I Stopped Trying to Self-Optimize, I Got Better by actionfromafar on Tuesday September 26, 2023 @11:55AM (#37661209)
tab trailing slash
Re:When I Stopped Trying to Self-Optimize, I Got Better by Izkata on Tuesday September 26, 2023 @09:11AM (#37658781)
For tar, I have memorized: x, c, z, j, v, f

The trick with tar that people seem to have issues with is the ordering with "f" - since it takes an argument, if you're using the combined short form it has to be last with the filename immediately following.

Re:When I Stopped Trying to Self-Optimize, I Got Better by Einenlum on Tuesday September 26, 2023 @07:34PM (#37667401)
Since a few years I only use dtrx. https://github.com/dtrx-py/dtrx/ I never have to learn this kind of stuff anymore.
Re:When I Stopped Trying to Self-Optimize, I Got Better by cosmojg on Monday September 25, 2023 @11:43PM (#37654042)
Fish's autocomplete makes life a lot easier, too. It's delightfully well designed.
Re:When I Stopped Trying to Self-Optimize, I Got Better by keyle on Tuesday September 26, 2023 @12:59AM (#37654605)
I head great things about Fish but I never took the dive.
Re:When I Stopped Trying to Self-Optimize, I Got Better by hiAndrewQuinn on Tuesday September 26, 2023 @02:45AM (#37655321)
I recommend it! Fish, starship.rs and `fzf` with the Ctrl+R and Alt+C keybindings continue to be my personal 80/20 for feeling comfy at the shell. Installing nvim and reloading my ~/.config using `chezmoi` gets me like 95% of the way there.

Being very obviously not Bash is a feature, not a bug, imo. It's usually pretty easy to turn Bash commands into Fish commands with the help of ChatGPT if you get stuck.

Re:When I Stopped Trying to Self-Optimize, I Got Better by petepete on Tuesday September 26, 2023 @06:34AM (#37657241)
My Fish shell is pretty indistinguishable from my Zsh one but it has 5% of the config. You get amazing completion, themes, highlighting, etc out of the box.

The only plugin I use is for fzf integration because I can't live without it.

Re:When I Stopped Trying to Self-Optimize, I Got Better by sertsa on Tuesday September 26, 2023 @01:08AM (#37654690)
How did I not know about ctrl+r? Feeling slightly more optimized
Re:When I Stopped Trying to Self-Optimize, I Got Better by hiAndrewQuinn on Tuesday September 26, 2023 @02:46AM (#37655336)
Wait until you try the `fzf` style Ctrl+R ;) total game changer for me.
Re:When I Stopped Trying to Self-Optimize, I Got Better by evilc00kie on Tuesday September 26, 2023 @01:23AM (#37654783)
Ctrl+R is insane but sometimes I have a hard time remembering flags due to overusing it. Especially when crafting new pipelines/solving new problems.

But I'd always alias some uncommon tasks and usages. Especially my quirky git ones:

  # get default branch
  alias gdefault='git remote show origin|grep -E HEAD|cut -d" " -f5'

  # cd to git root
  alias groot='cd "$(git rev-parse --show-toplevel)"'

  # Revert last unpushed commit to the state before commiting
  alias uncommit="git reset HEAD~1 --soft"

  # Show all commits between head and main as one-liner
  alias gl1="git log --reverse --oneline HEAD...\`gdefault\`"
Re:When I Stopped Trying to Self-Optimize, I Got Better by pdmccormick on Tuesday September 26, 2023 @01:55AM (#37655002)
Funny, I was just learning about Git revision ranges the other day, to get to something like the last one! Thanks for sharing.
Re:When I Stopped Trying to Self-Optimize, I Got Better by anbotero on Tuesday September 26, 2023 @01:53AM (#37654990)
I used to do this, but with fish shell unless I have very similar commands, I just type part of the whole line to something I (personally) associate it with and that’s it, that’s the command.

I press a space before commands with sensitive information so they don’t stay in my history or throwaway commands that I’m 99% sure I won’t use again.

Complicated ones I create a function for it, but I no longer carry aliases on my shell configuration, and I prefer the legibility of my commands/history.

Re:When I Stopped Trying to Self-Optimize, I Got Better by heavenlyblue on Tuesday September 26, 2023 @07:04AM (#37657501)
history | grep in regular bash
Re:When I Stopped Trying to Self-Optimize, I Got Better by pferde on Tuesday September 26, 2023 @07:24AM (#37657662)
Or ^Rpartofcommand to do an interactive history search.

This is a priceless feature, which, as I keep finding out, too many people do not know about, and they waste time faffing about pressing up and down, trying to find that one command their entered ten minutes ago. :)

Re:When I Stopped Trying to Self-Optimize, I Got Better by sambazi on Tuesday September 26, 2023 @02:11AM (#37655092)
> alias ss="git status"

ss is actually a 'socket stats' and will list all active connections while resolving their reverse dns name, be careful

Re:When I Stopped Trying to Self-Optimize, I Got Better by keyle on Tuesday September 26, 2023 @02:33AM (#37655221)
thanks, I know :)
Re:When I Stopped Trying to Self-Optimize, I Got Better by lenkite on Tuesday September 26, 2023 @03:04AM (#37655509)
This is why I prefer community standard aliases like Oh-my-zsh. All the conflicts get caught sooner by multiple people.
Re:When I Stopped Trying to Self-Optimize, I Got Better by Noumenon72 on Tuesday September 26, 2023 @04:46AM (#37656306)
Is there any harm in that?
Re:When I Stopped Trying to Self-Optimize, I Got Better by sambazi on Tuesday September 26, 2023 @05:37AM (#37656751)
the swath of dns-requests from calling ss on a machine with a lot of connections can trigger rate-limiting from the dns-server which in turn can disrupt other things.

i wish this was hypothetical

Re:When I Stopped Trying to Self-Optimize, I Got Better by bayindirh on Tuesday September 26, 2023 @04:55AM (#37656375)
If you're not a sysadmin or debugging your netork, no. However if you're using it for any reason, you lose a command. This is why I start my local commands with a comma (,) [0].

[0]: https://rhodesmill.org/brandon/2009/commands-with-comma/

Re:When I Stopped Trying to Self-Optimize, I Got Better by Zambyte on Tuesday September 26, 2023 @07:41AM (#37657830)
/bin/ss will still work.
Re:When I Stopped Trying to Self-Optimize, I Got Better by bayindirh on Tuesday September 26, 2023 @07:44AM (#37657861)
Why should I need to write a longer command for something I routinely use, while ",[tab][tab]" would bring all my aliases/custom commands?
Re:When I Stopped Trying to Self-Optimize, I Got Better by Zambyte on Tuesday September 26, 2023 @10:05AM (#37659508)
... then don't use the alias.

You said:

> you lose a command

I showed you how you do not lose a command. That is all.

Re:When I Stopped Trying to Self-Optimize, I Got Better by bayindirh on Tuesday September 26, 2023 @10:21AM (#37659777)
This is what I do. I don't use aliases.

> I showed you how you do not lose a command. That is all.

I know. I understand your point, but yours is a very pedantic (sorry, was unable to find a gentler word) take on the issue.

In the heat of debugging some prod problems, the need to remember which commands are overridden by aliases and the effort required to remember full paths is an extra mental load. This is why it's better to not use aliases or be super careful, or at least prefix them with a common character is useful.

There's something called scaling cost. It's not only valid for infrastructure or software architecture. The customization you do, or the procedures you follow need to be able to scale too. I recently had to abandon Tiddly Wiki for Obsidian, because the work required to maintain that corpus of information became accidentally quadratic, and started to eat into my productivity and time. Aliases and terminal customization are also affected by this phenomena.

Re:When I Stopped Trying to Self-Optimize, I Got Better by rpastuszak on Tuesday September 26, 2023 @03:30AM (#37655725)
Re:When I Stopped Trying to Self-Optimize, I Got Better by maccard on Tuesday September 26, 2023 @03:44AM (#37655840)
> Everyone does this. Otherwise you'd go bat sh*t crazy trying to remember every intricate details of common tools.

I've got some bad news for you...

Re:When I Stopped Trying to Self-Optimize, I Got Better by Kiro on Tuesday September 26, 2023 @05:54AM (#37656908)
Everyone is definitely not doing this. I would say the vast majority doesn't even know how to set up an alias.
Re:When I Stopped Trying to Self-Optimize, I Got Better by tomatocracy on Tuesday September 26, 2023 @07:53AM (#37657954)
Ctrl+R is nice, and was a big quality of life improvement when I first found out about it.

Recently I've found a similar improvement going from "plain old" ctrl+r for history to a set of zsh extensions plus fzf - my current set of extensions is zsh-autocomplete, zsh-autosuggestions, zsh-syntax-highlighting, zsh-history-substring-search, zsh-histdb, and fzf-histdb.

Re:When I Stopped Trying to Self-Optimize, I Got Better by bbkane on Tuesday September 26, 2023 @11:06PM (#37669432)
That sounds super similar my setup ( https://github.com/bbkane/dotfiles/tree/master/zsh ). I'll check out a few of those I haven't yet.
Re:When I Stopped Trying to Self-Optimize, I Got Better by tomatocracy on Wednesday September 27, 2023 @04:29AM (#37671763)
Some interesting ones there and sounds like you have a similar philosophy to me - don't customize to the point that context-switching to bash is a pain.

For tab-completion I actually prefer the builtin zsh completer set to use the menu mode - this is one of the big improvements you get with zsh over bash / etc to my mind. I have in .zshrc

  zstyle ':completion:*' menu select=2 select=long interactive
You can set it to use your ls colors with something like

  zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}"
Re:When I Stopped Trying to Self-Optimize, I Got Better by fouc on Tuesday September 26, 2023 @08:21AM (#37658198)
> Everyone does this

I disagree, experienced *nix users probably remember a TON of commands outright, after going through multiple distros/*nixes over the years.

Personally I have maybe ~30 aliases that are actually used. There's almost no point in inventing aliases that will go unused or be rapidly forgotten etc.

git has it's own alias config which I prefer to use instead. some examples: st=status, co=checkout, ci=commit, cp = cherry-pick, mod=add -u.

so that means I do 'g st' instead of 'ss', yeah, a couple extra keypresses but I'm okay with that.

Re:When I Stopped Trying to Self-Optimize, I Got Better by cosmojg on Monday September 25, 2023 @11:41PM (#37654033)
Welcome to Unix! :)
Re:When I Stopped Trying to Self-Optimize, I Got Better by pdmccormick on Tuesday September 26, 2023 @01:27AM (#37654824)
Thanks, 25 years in and I'm still learning new things. But I don't think I was specifically shouting out the Unix philosophy. My comment was more in response to the OP article, that rather than "trying" to optimize in the sense that you already know what you need to optimize for and towards, instead thinking of self-improvement as being a by-product of being able to think new thoughts, thus the upfront emphasis on the acquisition of new language (with a big nod to the Sapir-Whorf hypothesis). This could be through collecting good terminology, best practise and patterns, and learning the philosophies of systems such as Unix and languages like Go and Python. However, with aliases and scripts, it becomes something you can actually "speak" in an effective sense, which ultimately can lead to improvements over earlier capabilities that go beyond what you could have envisioned as possible from the start.

I took a handful of math courses in school, and what I didn't realize till later was that learning how to rigourously prove things mathematically had dramatically reshaped my mind. I am left wondering what it must be like for the minds of those who have traversed that tower far higher than I ever have or will.

Re:When I Stopped Trying to Self-Optimize, I Got Better by stephen_cagle on Tuesday September 26, 2023 @12:52AM (#37654552)
That's an interesting idea. Did you write a script to identify commands that you use repeatedly? I wonder how that could best be done?
Re:When I Stopped Trying to Self-Optimize, I Got Better by pdmccormick on Tuesday September 26, 2023 @01:40AM (#37654901)
I have not tried that yet, no. For me the goal isn't just about shortening often repeated commands, as though the limitation were purely about character input speed, it's more of a contemplative practise of learning how to notice and respond to that internal prompt that says "I wish I could say that more succinctly" or "There has to be a better way to do this". And then either telling my mind work on those questions, or being open and receptive to coming across something relevant on the topic, or seizing a moment of inspiration to write a time-saving script or come up with a meaningful (to me) alias.
Re:When I Stopped Trying to Self-Optimize, I Got Better by crosa on Tuesday September 26, 2023 @03:22AM (#37655666)
Re:When I Stopped Trying to Self-Optimize, I Got Better by 63 on Tuesday September 26, 2023 @02:19AM (#37655127)
Must be nice being able to work in the same shell every day, and one you have complete control over no less. For those of us ssh-ing into uncountable remote servers all day with unprivileged accounts, it's not really a practical option unfortunately.
Re:When I Stopped Trying to Self-Optimize, I Got Better by bheadmaster on Tuesday September 26, 2023 @02:26AM (#37655178)
If your utilities are written as self-contained exported Bash functions, you could concatenate them all in a single file (say, `utils.sh`), with a single line at the end:

    exec /bin/bash
Then you could do something like:

    ssh hostname@address -tt bash -s < /path/to/utils.sh
And have all your utilities available on the remote machine :)
Re:When I Stopped Trying to Self-Optimize, I Got Better by Noumenon72 on Tuesday September 26, 2023 @04:48AM (#37656325)
Does this work for aliases?
Re:When I Stopped Trying to Self-Optimize, I Got Better by pdmccormick on Tuesday September 26, 2023 @03:26AM (#37655691)
By "personal computing" I guess I do mean machines that I have full root on, so usually either a laptop/desktop or a local headless server.

Out of curiousity, these servers that you're dealing with, do you have to use them for long/focused work like writing or software development, or are these more like sysadmin interactions? Have you noticed any repeated commands or sequences you find yourself running over and over? Is there any opportunity for you to write local scripts that then SSH into the targets and run those commands on your behalf? Or locally use sshfs and manipulate files like they were local.

Re:When I Stopped Trying to Self-Optimize, I Got Better by j7ake on Tuesday September 26, 2023 @05:29AM (#37656674)
Would love a system that analyses my shell command usage and recommend when I should link commands I often use in series and turn them into one line.

It’s more than just frequency analysis because it helps to remember what commands happened before or after. It also needs to be smart about when two commands are actually “the same thing” but with different flags or input filenames.

Maybe something like an N-gram model.

Re:When I Stopped Trying to Self-Optimize, I Got Better by williamdclt on Tuesday September 26, 2023 @05:48AM (#37656853)
I don't like being this guy, but maybe throwing your history at a GPT, asking it exactly that, would work fairly well?
Re:When I Stopped Trying to Self-Optimize, I Got Better by ChrisMarshallNY on Tuesday September 26, 2023 @06:10AM (#37657038)
For me, personally, I’ve never been particularly interested in self-metering.

It does have its place, though. Each morning, I do a 5K walk, and am constantly glancing at my Apple Watch, to ensure I maintain a pace of <10 min/K. If I find myself slowing, I put on a bit of mainsail, but I don’t insist on beating my personal best.

As for my software development, I just enjoy the work, and have dealt with CRS[0], since I was about 17. It’s always been a basic challenge, and isn’t something I can control.

It’s made me very good at finding information quickly and relevantly. I’m really good at googling answers; even embarrassingly basic ones.

My work speaks for itself. I definitely perform at a pretty high level. There are many folks that are better than me, but many, many more that can’t do as well.

[0] https://www.urbandictionary.com/define.php?term=CRS