This is exactly the kind of stuff I'm most interested in finding on HN. How do other developers work, and how can I get better at my work from it? What's always interesting to me is how many of these I'll see and initially think, "I don't really need that." Because I'm well aware of the effect (which I'm sure has a name - I suppose it's similar to induced demand) of "make $uncommon_task much cheaper" -> "$uncommon_ta…
https://raw.githubusercontent.com/fliptheweb/bash-shortcuts-... has served me very well.
Scripts I wrote that I use all the time
401–408 of 408 posts
Re: Scripts I wrote that I use all the time
#402alias df='duf'
alias ls='eza'
alias ll='eza -l'
alias cat='bat'
alias cap='bat -p'
alias man='tldr'
alias top='glances'
alias grep='rg'
alias ps='procs'
alias cd='z'
alias g='gitui'
alias gs='git st'
alias gp='git pull'
alias gu='git add . && git commit -m "Update" && git push'
alias check='shellcheck'
alias v='nvim'
alias len='wc -l'
alias uuid='uuidgen'
alias src='source ~/.zshrc'
Re: Scripts I wrote that I use all the time
#403I use my "dc" command to reverse "cd" frequently https://gist.github.com/GNOMES/6bf65926648e260d8023aebb9ede9... Ex: > echo $PWD /foo/bar/batz/abc/123 > dc bar && echo $PWD /foo/bar Useful for times when I don't want to type a long train of dot slashes(ex. cd ../../..). Also useful when using Zoxide, and I tab complete into a directory tree path where parent directories are not in Zoxide history. Added tab complete f…
> dc is the oldest surviving Unix language program.
https://en.wikipedia.org/wiki/Dc_%28computer_program%29
I used "dc" (the calculator) just earlier this week. Kids these days? :)
Re: Scripts I wrote that I use all the time
#404Earlier quoted context omitted.
If you write these sorts of things in Python, argparse is worth investigating: https://docs.python.org/3/library/argparse.html - it's pretty easy to use, makes it easy to separate the command line handling from the rest of the code, and, importantly, will generate a --help page for you. And if you want something it can't do, you can still always write the code yourself!
I don’t like Python in general, but even so I’ll say that argparse is indeed very nice. When I was writing ruby, I always felt that OptionParser¹ wasn’t as good. Swift has Argument Parser², officially from Apple, which is quite featureful. For shell, I have a a couple of bespoke patterns I have been reusing in every script for many years. ¹ https://github.com/ruby/optparse ² https://github.com/apple/swift-argument-pa…
https://github.com/p-ranav/argparse is a single-file argparse for Modern C++, which means it's typically straightforward, if baffling in places and a bit annoying to step through in the debugger.
The nice thing about the argparse ports is that provided they take their job seriously, your programs will all end up with a vaguely consistent command line UX in terms of longopt syntax, and, importantly, a --help page.
Re: Scripts I wrote that I use all the time
#405Earlier quoted context omitted.
Good point, when working with keybindings, you'll inevitably end up overriding built-ins. I see it as a trade-off, between something I don't know of (and wouldn't use) and something I find useful. Works for me :)
absolutely. From back in the day, the annoying one was GNU screen, which took over ctrl-a by default. Overrode that to be ctrl-^, which in bash is transpose, make "zx be "xz", which was rare enough to okay with losing.
Re: Scripts I wrote that I use all the time
#406With `xsel --clipboard` (put that in an alias like `clip`), you can use the same thing to replace both `copy` and `pasta`: # High level examples run_some_command | clip clip > file_from_my_clipboard.txt # Copy a file's contents clip
Re: Scripts I wrote that I use all the time
#407Re: Scripts I wrote that I use all the time
#408> trash a.txt b.png moves `a.txt` and `b.png` to the trash. Supports macOS and Linux. The way you’re doing it trashes files sequentially, meaning you hear the trashing sound once per file and ⌘Z in the Finder will only restore the last one. You can improve that (I did it for years) but consider just using the `trash` commands which ships with macOS. Doesn’t use the Finder, so no sound and no ⌘Z, but it’s fast, offici…
Instead of trash, reimplementing rm (to only really delete after some time or depending on resource usage or to shred of you are paranoid if the goal is to really delete something) or using zfs makes much more sense.