12 ms·
Scripts I wrote that I use all the time
- rcarmo 1y agoAs a fun game, I suggest feeding the entire piece to an LLM and asking it to create those scripts. The differences between Claude, GOT-5 and Gemini are very interesting.
- munchlax 1y agomksh is already the MirBSD Korn SHell
- rauli_ 1y agoWhich very very few people have actually installed on their system.
- thibran 1y ago30% of the productivity hacks can be archived in vanilla Nushell.
- weregiraffe 1y agoLooks very useful!
- southwindcg 1y agoRegarding the `line` script, just a note that sed can print an arbitrary line from a file, no need to invoke a pipeline of cat, head, and tail: sed -n 2p file prints the second line of file. The advantage sed has over this line script is it can also print more than one line, should you need to: sed -n 2,4p file prints lines 2 through 4, inclusive.
- tonmoy 1y agoIt is often useful to chain multiple sed commands and sometimes shuffle them around. In those cases I would need to keep changing the fist sed. Sometimes I need to grep before I sed. Using cat, tail and head makes things more modular in the long run I feel. It’s the ethos of each command doing one small thing
- southwindcg 1y agoTrue, everything depends on what one is trying to do at the time.
- 1-more 1y agoyeah I almost always start with `cat` but I still pipe it into `sed -n 1,4p`
- mmsc 1y agoIf you'd like to print the middle of a file, try out `body`: https://github.com/megamansec/body https://github.com/megamansec/body
- wiether 1y agoIt's been a while since I haven't read something as useful! There also some very niche stuff that I won't use but found funny
- giraffe_lady 1y agoThe nato phonetic alphabet one cracked me up. My dude you don't need that, call center employees don't know it, just say S as in Sugar like ur grandma used to.
- ericyd 1y agoThe nato phonetic alphabet is still useful even if the other party doesn't know it, I've used it a bunch of times on the phone to spell out my 10- letter last name. Saves quite a lot of time and energy for me vs saying "letter as in word" for each letter.
- deleted 1y ago[deleted]
- SoftTalker 1y ago> saying "letter as in word" for each letter Which often just confuses things further. Me: My name is "Farb" F-A-R-B. B as in Baker. Them: Farb-Baker, got it.
- giraffe_lady 1y ago"M as in Mancy."
- giraffe_lady 1y agoRight but it's not much more useful than any other phonetic alphabet the other party doesn't know, including the one you make up on the spot.
- sfink 1y ago
- soiltype 1y agoThis 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_task becomes the basis of an entirely new workflow/skill". So I'm going to try out most of them and see what sticks! Also: really love the style of the post. It's very clear but also includes super valuable information about how often the author actually uses each script, to get a sense ahead of time for which ones are more likely to trigger the effect described above. A final aside about my own workflows which betrays my origins... for some of these operations and for others i occasionally need, I'll just open a browser dev tools window and use JS to do it, for example lowercasing a string :)
- chipsrafferty 1y agoI'd love to see a cost benefit analysis of the author's approach vs yours, which includes the time it took the author to create the scripts, remember/learn to use them/reference them when forgetting syntax, plus time spent migrating whenever changing systems.
- te_cima 1y agowhy is this interesting to you? the whole point of doing all of this is to be more efficient in the long run. of course there is an initial setup cost and learning curve after which you will hopefully feel quite efficient with your development environment. you are making it sound like it is not worth the effort because you have to potentially spend time learning "it"? i do not believe that it takes long to "learning" it, but of course it can differ a lot from person to person. your remarks seem like non-issues to me.
- akersten 1y agoIt's interesting because there's a significant chance one wastes more time tinkering around with custom scripts than saving in the long run. See https://xkcd.com/1205/ https://xkcd.com/1205/ For example. The "saves 5 seconds task that I do once a month" from the blog post. Hopefully the author did not spend more than 5 minutes writing said script and maintaining it, or they're losing time in the long run.
- pmontra 1y agoI also have a radio script to play internet streams with mpv (?). Other random stuff A password or token generator, simple or complicated random text. Scripts to list, view and delete mail messages inside POP3 servers n, to start Nautilus from terminal in the current directory. lastpdf, to open the last file I printed as PDF. lastdownload, to view the names of the n most recent files in the Downloads directory. And many more but those are the ones that I use often and I remember without looking at ~/bin
- oceanplexian 1y agoIt's weird how the circle of life progresses for a developer or whatever. - When I was a fresh engineer I used a pretty vanilla shell environment - When I got a year or two of experience, I wrote tons of scripts and bash aliases and had a 1k+ line .bashrc the same as OP - Now, as a more tenured engineer (15 years of experience), I basically just want a vanilla shell with zero distractions, aliases or scripts and use native UNIX implementations. If it's more complicated than that, I'll code it in Python or Go.
- D13Fd 1y agoI would still call my Python scripts “scripts.” I don’t think the term “scripts” is limited to shell scripts.
- trenchpilgrim 1y agoWhen I had one nix computer, I wanted to customize it heavily. Now I have many nix computers and I want them consistent and with only the most necessary packages installed.
- ozim 1y agoBesides many nix computers I also have wife, dog, children, chores, shopping to be done. Unlike when I was young engineer I could stay all night fiddling with bash scripts and environments.
- soraminazuki 1y agoWhat does your wife, dog, children, chores, and shopping have to do with custom configuration and scripts? Just set up a Git repo online, put your files there, and take a couple of minutes to improve it incrementally when you encounter inconveniences. And just like that, you made your life easier for a marginal effort.
- 1718627440 1y agoThey compete for time.
- vunderba 1y agoNice. I have a bash script similar to the one listed "removeexif" called prep_for_web which takes any image file (PNG, BMP, JPG, WebP), scrubs EXIF data, checks for transparency and then compresses it to either JPG using MozJPEG or to PNG using PNGQuant. [1] https://github.com/mozilla/mozjpeg https://github.com/mozilla/mozjpeg [2] https://pngquant.org https://pngquant.org
- SoftTalker 1y agoSome cool things here but in general I like to learn and use the standard utilities for most of this. Main reason is I hop in and out of a lot of different systems and my personal aliases and scripts are not on most of them. sed, awk, grep, and xargs along with standard utilities get you a long long way.
- pinkmuffinere 1y agoI totally agree with this, I end up working on many systems, and very few of them have all my creature comforts. At the same time, really good tools can stick around and become impactful enough to ship by default, or to be easily apt-get-able. I don't think a personal collection of scripts is the way, but maybe a well maintained package.
- scoodah 1y agoSame. I interact with too many machines, many of which are ephemeral and will have been reprovisioned the next time I have to interact with it. I value out of the box stuff that works most everywhere. I have a fairly lightweight zsh config I use locally but it’s mostly just stuff like a status like that suits me, better history settings, etc. Stuff I won’t miss if it’s not there.
- dannyobrien 1y agoHistorical note: getting hold of these scripts by chatting to various developers was the motivation for the original 2004 "lifehacks" talk[1][2]. If you ever get into an online argument over what is a "life hack" and what isn't, feel free to use short scripts like these as the canonical example. Otherwise, I am happy to be pulled into your discussion, Marshall McLuhan style[3] to adjudicate, for a very reasonable fee. [1] https://craphound.com/lifehacksetcon04.txt https://craphound.com/lifehacksetcon04.txt [2] https://archive.org/details/Notcon2004DannyOBrienLifehacks https://archive.org/details/Notcon2004DannyOBrienLifehacks [3] https://www.openculture.com/2017/05/woody-allen-gets-marshall-mcluhan-to-put-a-pontificating-professor-in-his-place.html https://www.openculture.com/2017/05/woody-allen-gets-marshal...
- deleted 1y ago[deleted]
- deleted 1y ago[deleted]
- helicaltwine 1y agoAs a bonus, I prepend my custom aliases or scripts with my user name and hyphen (i.e helicaltwine-). It helps me recall rarely used scripts when I need them and forget the names.
- dunb 1y agoI follow a similar but more terse pattern. I prepend them all with a comma, and I have yet to find any collisions. If you're using bash (and I assume posix sh as well), the comma character has no special meaning, so this is quite a nice use for it. I agree that it's nice to type ",<tab>" and see all my custom scripts appear.
- headgasket 1y agoif you use x0vnc (useful if you use a linux machine both from the attached screen and from vnc, and in a bunch of other scenarios), copy and paste to and fro the vnc client is not implemented, quite frustrating. here's 2 scripts that does that for you, I now use this all day. https://github.com/francoisp/clipshare https://github.com/francoisp/clipshare
- latexr 1y ago> 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, official, and still allows “Put Back”. > jsonformat takes JSON at stdin and pretty-prints it to stdout. Why prioritise node instead of jq? The latter is considerably less code and even comes preinstalled with macOS, now. > uuid prints a v4 UUID. I use this about once a month. Any reason to not simply use `uuidgen`, which ships with macOS and likely your Linux distro? https://www.man7.org/linux/man-pages/man1/uuidgen.1.html https://www.man7.org/linux/man-pages/man1/uuidgen.1.html
- derintegrative 1y agoOn Linux you also have % cat /proc/sys/kernel/random/uuid 464a4e91-5ce4-47b6-bb09-8a60fde572fb
- sedatk 1y agoand it's `New-Guid` in PowerShell.
- rbonvall 1y agoPython also pretty-prints out of the box: $ echo '{ "hello": "world" }' | python3 -m json.tool { "hello": "world" }
- tester457 1y agoI am not the author, but my bet is that he didn't know of its existence. The best part about sharing your config or knowledge is that someone will always light up your blind spots.
- gigatexal 1y agoExactly! I didn’t know macOS ships JQ or the uuidgen tool. Very cool
- 1y ago
- jrm4 1y agoBroadly, I very much love this approach to things and wish it was more "acceptable?" It reminds me of the opposite of things like "the useless use of cat" which to me is one of the WORST meme-type-things in this space. Like, it's okay -- even good -- for the tools to bend to the user and not the other way around.
- yipbub 1y agoI have mkcd exactly ( I wonder how many of us do, it's so obvious) I have almost the same, but differently named with scratch(day), copy(xc), markdown quote(blockquote), murder, waitfor, tryna, etc. I used to use telegram-send with a custom notification sounnd a lot for notifications from long-running scripts if I walked away from the laptop. I used to have one called timespeak that would speak the time to me every hour or half hour. I have go_clone that clones a repo into GOPATH which I use for organising even non-go projects long after putting go projects in GOPATH stopped being needed. I liked writing one-offs, and I don't think it's premature optimization because I kept getting faster at it.
- justusthane 1y agoObviously that script is more convenient, but if you’re on a system where you don’t have it, you can do the following instead: mkdir /some/dir cd !$ (or cd <alt+.>)
- taejavu 1y agoDoesn’t the built in `take` do exactly what `mkcd` does? Or is `take` a zsh/macos specific thing? Edit: looks like it’s a zsh thing
- codesnik 1y agoit's an .oh-my-zsh thing (~/.oh-my-zsh/lib/functions.zsh) but thanks, I didn't know about it.
- linsomniac 1y ago>I have mkcd exactly ( I wonder how many of us do, it's so obvious) Mine is called "md" and it has "-p" on the mkdir. "mkdir -p $1 && cd $1"
- mttpgn 1y agoI too have a `mkcd` in my .zshrc, but I implemented it slightly differently: function mkcd { newdir=$1 mkdir -p $newdir cd $newdir }
- 1y ago
- WhyNotHugo 1y ago> cpwd copies the current directory to the clipboard. Basically pwd | copy. I often use this when I’m in a directory and I want use that directory in another terminal tab; I copy it in one tab and cd to it in another. I use this once a day or so. You can configure your shell to notify the terminal of directory changes, and then use your terminal’s “open new window” function (eg: ctrl+shift+n) to open a new window retaining the current directory.
- yegle 1y agoThe markdownquote can be replaced by (at least in vim): ^ (jump to the beginning) ctrl+v (block selection) j (move cursor down) shift+i (bulk insert?) type ><space> ESC
- javier123454321 1y ago:'<,'>s/.*$/> \0/ also
- ginsider_oaks 1y agoor even better: :'<,'>s/^/> /
- javier123454321 1y agoDuh, yeah youre right. This wins.
- fragmede 1y agoWhere are the one letter aliases? My life got better after I alias k=kubectl
- interestica 1y agoShare yours! I use this as a bookmarklet to grab the front page of the new york times (print edition). (You can also go back to any date up to like 2011) I think they go out at like 4 am. So, day-of, note that it will fail if you're in that window before publishing. javascript:(()=>{let d=new Date(new Date().toLocaleString('en-US',{timeZone:'America/New_York'})),y=d.getFullYear(),m=('0'+(d.getMonth()+1)).slice(-2),g=('0'+d.getDate()).slice(-2);location.href=`https://static01.nyt.com/images/${y}/${m}/${g}/nytfrontpage/scan.pdf`})()
- xiphias2 1y agoAn important advantage of aliases was not mentioned: I see everything in one place and can easily build aliases on top of other aliases without much thinking. Anyways, my favourite alias that I use all the time is this: alias a='nvim ~/.zshrc && . ~/.zshrc' It solves the ,,not loaded automatically'' part at least for the current terminal
- o11c 1y agoI keep meaning to generalize this (directory target, multiple sources, flags), but I get quite a bit of mileage out of this `unmv` script even as it is: #!/bin/sh if test "$#" != 2 then echo 'Error: unmv must have exactly 2 arguments' exit 1 fi exec mv "$2" "$1"
- alentred 1y ago> alphabet just prints the English alphabet in upper and lowercase. I use this surprisingly often (probably about once a month) I genuinely wonder, why would anyone want to use this, often?
- dcassett 1y agoFor me it's when I call customer service or support on the phone, and either give them an account #, or confirm a temporary password that I have been verbally given.
- Tempest1981 1y agoAre you referring to the nato alphabet utility? Or the alphabet script that prints abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ
- CGamesPlay 1y agoIf your native language uses a different alphabet, you might not have been taught "the alphabet song". For example, I speak/read passable Russian, but could not alphabetize a list in Russian.
- abetusk 1y agoAs a programmer, you sometimes want to make an alphabet lookup table. So, something like: var alpha_lu = "abcdefghijklmnopqrstuvwxyz"; Typing it out by hand is error prone as it's not easy to see if you've swapped the order or missed a character. I've needed the alphabet string or lookup rarely, but I have needed it before. Some applications could include making your own UUID function, making a small random naming scheme, associating small categorical numbers to letters, etc. The author of article mentioned they do web development, so it's not hard to imagine they've had to create a URL shortener, maybe more than once. So, for example, creating a small name could look like: function small_name(len) { let a = "abcdefghijklmnopqrstuvwxyz", v = []; for (let i=0; i<len; i++) { v.push( a[ Math.floor( Math.random()*a.length ) ] ); } return v.join(""); } //... small_name(5); // e.g. "pfsor" Dealing with strings, dealing with hashes, random names, etc., one could imagine needing to do functions like this, or functions that are adjacent to these types of tasks, at least once a month. Just a guess on my part though.
- revicon 1y agoI have a bunch of little scripts and aliases I've written over the years, but none are used more than these... alias ..='cd ..' alias ...='cd ../..' alias ....='cd ../../..' alias .....='cd ../../../..' alias ......='cd ../../../../..' alias .......='cd ../../../../../..'
- Bishonen88 1y agoup() { local d="" for ((i=1; i<=$1; i++)); do d="../$d" done cd "$d" } up 2, up 3 etc.
- vunderba 1y agoDoes zsh support this out-of-the-box? Because I definitely never had to setup any of these kinds of aliases but have been using this shorthand dot notation for years.
- machomaster 1y agoYes it does.
- Noumenon72 1y agoNot on my Mac. zsh: permission denied: .. zsh: command not found: ...
- soraminazuki 1y agoIt's an oh-my-zsh thing.
- tacone 1y agoI have setup a shortcut: alt+. to run cd.., it's pretty cool. I also aliased - to run cd -
- fragmede 1y agobut alt-. in bash is used for pasting the last argument to the previous command into the current one.
- holyknight 1y agocool collection
- sedatk 1y ago> `rn` prints the current time and date using date and cal. And you can type `rn -rf *` to see all timezones recursively. :)
- javier123454321 1y agoThis is one area that I've found success in vibe coding with. Making scripts for repetitive tasks that are just above the complexity threshold where the math between automating and doing manually is not so clear. I have copilot generate the code for me and honestly I don't care too much of its quality, extensibility, and are easy enough to read through where I don't feel like my job is AI pr reviewer.
- samtrack2019 1y agono offense but a lot of those script are pretty hacky they may work for the user but i would not use them without making sure to review them and adapt them to my workflow
- ziotom78 1y agoThat's a fair point. I think the author intended the post to be a treasure trove of ideas for your own scripts, not as something to blindly include in your daily workflow.
- nberkman 1y agoNice! Tangentially related: I built a (MacOS only) tool called clippy to be a much better pbcopy. It was just added to homebrew core. Among other things, it auto-detects when you want files as references so they paste into GUI apps as uploads, not bytes. clippy image.png # then paste into Slack, etc. as upload clippy -r # copy most recent download pasty # copy file in Finder, then paste actual file here https://github.com/neilberkman/clippy https://github.com/neilberkman/clippy / brew install clippy
- Tempest1981 1y agoAdding the word "then" to your first comment would have helped me: (lacking context, I thought the comments explained what the command does, as is common convention) clippy image.png # then paste into Slack, etc. as upload Also: pasty # paste actual file, after copying file in Finder
- nberkman 1y agoUpdated, I appreciate it!
- gigatexal 1y agoAwesome. Gonna check this out.
- some_guy_nobel 1y agoThese are great, and I have a few matching myself. Here are some super simple ones I didn't see that I use almost every day: cl="clear" g="git" h="history" ll="ls -al" path='echo -e ${PATH//:/\\n}' lv="live-server" And for common navigation: dl="cd ~/Downloads" dt="cd ~/Desktop"
- fragmede 1y agok=kubectl
- hackeraccount 1y agoI'm terrible about remembering shortcuts (edit a bash line in an editor? Can never remember it) but clear (CTRL-l) is one that really stuck. That and exit (CTRL-d). A guy I used to work with just mentioned it casually and someone it just seared itself into my brain.
- some_guy_nobel 1y agoNever new ctrl+l, that's great, thanks!
- virgoerns 1y agoFYI, ctrl-d isn't a shortcut to exit terminal. It sends EOF (end of file) character which, when reaches shell, closes stdinput file of shell. It generally closes any active interactive input, like all repls, interactive input to sed etc. When interactive shell loses possibility to get more input, it closes as soon as possible and then its parent, the terminal window, also closes. More-less :)
- deleted 1y ago[deleted]
- vzaliva 1y agoA lot of these scripts could be just shell aliases.
- 27theo 1y agoOP links to a long blog post with reasons for using scripts https://evanhahn.com/why-alias-is-my-last-resort-for-aliases/ https://evanhahn.com/why-alias-is-my-last-resort-for-aliases...
- chasil 1y agoI like this one. $ cat /usr/local/bin/awkmail #!/bin/gawk -f BEGIN { smtp="/inet/tcp/0/smtp.yourco.com/25"; ORS="\r\n"; r=ARGV[1]; s=ARGV[2]; sbj=ARGV[3]; # /bin/awkmail to from subj < in print "helo " ENVIRON["HOSTNAME"] |& smtp; smtp |& getline j; print j print "mail from:" s |& smtp; smtp |& getline j; print j if(match(r, ",")) { split(r, z, ",") for(y in z) { print "rcpt to:" z[y] |& smtp; smtp |& getline j; print j } } else { print "rcpt to:" r |& smtp; smtp |& getline j; print j } print "data" |& smtp; smtp |& getline j; print j print "From:" s |& smtp; ARGV[2] = "" # not a file print "To:" r |& smtp; ARGV[1] = "" # not a file if(length(sbj)) { print "Subject: " sbj |& smtp; ARGV[3] = "" } # not a file print "" |& smtp while(getline > 0) print |& smtp print "." |& smtp; smtp |& getline j; print j print "quit" |& smtp; smtp |& getline j; print j close(smtp) } # /inet/protocol/local-port/remote-host/remote-port
- alberand 1y agoMy fav script to unpack anything, found a few years ago somewhere # ex - archive extractor # usage: ex <file> function ex() { if [ -f $1 ] ; then case $1 in *.tar.bz2) tar xjf $1 ;; *.tar.gz) tar xzf $1 ;; *.tar.xz) tar xf $1 ;; *.bz2) bunzip2 $1 ;; *.rar) unrar x $1 ;; *.gz) gunzip $1 ;; *.tar) tar xf $1 ;; *.tbz2) tar xjf $1 ;; *.tgz) tar xzf $1 ;; *.zip) unzip $1 ;; *.Z) uncompress $1;; *.7z) 7z x $1 ;; *) echo "'$1' cannot be extracted via ex()" ;; esac else echo "'$1' is not a valid file" fi }
- rbonvall 1y agoI use dtrx, which also ensures that all files are extracted into a folder.
- alanbernstein 1y ago`aunpack` does the trick for me.
- manbitesdog 1y agoThat's brilliant. Now I need its compressing counterpart.
- alberand 1y agoFor compression, I have one for .tar.gz. But it's not that popular in my system. I need something a bit easier than 'pack file file file archive.tar.gz'
- gigatexal 1y agoVery nice and clean
- YouAreWRONGtoo 1y agoNow, add inotify and a systemd user service and you would be getting somewhere. Also packaged versions of that exist already. So, you created a square wheel, instead of a NASA wheel.
- SuperHeavy256 1y agoI hope to see an operating system with these scripts as built-in, because they are so intuitive and helpful! Which OS will be the first to take this on?
- CrimpCity 1y agoLately I’ve been using caffeinate to run long running scripts without interruption from sleep on Mac. Nothing crazy but could be useful to newer devs.
- sid- 1y agoWhy dont we have mkcd in linux natively boggles my mind :)
- taejavu 1y agozsh has a `take` utility that is exactly this
- marcuskaz 1y agoLikewise, why doesn't git clone automatically cd into the repo?
- andriamanitra 1y agoA subprocess (git) can't modify the working directory of the parent process (the shell). This is a common annoyance with file managers like yazi and ranger as well—you need an extra (usually manual!) installation step to add a shell integration for whichever shell you're using so the shell itself can change directory. The best solution for automatically cd'ing into the repo is to wrap git clone in a shell function or alias. Unfortunately I don't think there's any way to make git clone print the path a repository was cloned to, so I had to do some hacky string processing that tries to handle the most common usage (ignore the "gh:" in the URL regex, my git config just expands it to "git@github.com:"): https://github.com/Andriamanitra/dotfiles/blob/d1aecb8c37f09bba0613f75056d379c2b055cca8/fish/.config/fish/functions/clo.fish https://github.com/Andriamanitra/dotfiles/blob/d1aecb8c37f09...
- Tempest1981 1y ago> alphabet just prints the English alphabet in upper and lowercase. I use this surprisingly often I'm curious to hear some examples (feel like I'm missing out)
- lillesvin 1y agoObviously, to each their own, but to me, this is an overwhelming amount of commands to remember on top of all the ones they are composed of that you will likely need to know anyway — regardless if all the custom ones exist. Like, I'd have to remember both `prettypath` and `sed`, and given that there's hardly any chance I'll not need `sed` in other situations, I now need to remember two commands instead of one. On top of that `prettypath` only does s/:/\\n/ on my path, not on other strings, making its use extremely narrow. But generally doing search and replace in a string is incredibly useful, so I'd personally rather just use `sed` directly and become more comfortable with it. (Or `perl`, but the point is the same.) As I said, that's obviously just my opinion, if loads of custom scripts/commands works for you, all the more power to you!
- cleartext412 1y agoFor someone using sed often enough inventing prettypath won't make sense. However, if producing correct sed command, be it by remembering the options, reading manual or digging through the shell history, takes some amount of mental effort, your brain will happily stick "prettypath" into memory as long as doing so stays less mentally taxing than doing original task from scratch.
- sorenjan 1y agoI got a ccurl python script that extracts the cookies from my Firefox profile and then passes those on to curl, that way I can get webpages where I'm logged in.
- naikrovek 1y ago> wifi toggle this fella doesn't know what "toggle" means. in this context, it means "turn off if it's currently on, or turn on if it's currently off." this should be named `wifi cycle` instead. "cycle" is a good word for turning something off then on again. naming things is hard, but it's not so hard that you can't use the right word. :)
- codesnik 1y agoor wifi toggle-toggle!
- Noumenon72 1y agoWhile you're creating and testing aliases, it's handy to source your ~/.zshrc whenever you edit it: alias vz="vim ~/.zshrc && . ~/.zshrc" I alias mdfind to grep my .docx files on my Mac: docgrep() { mdfind "\"$@\"" -onlyin /Users/xxxx/Notes 2> >(grep --invert-match ' \[UserQueryParser\] ' >&2) | grep -v -e '/Inactive/' | sort } I use an `anon` function to anonymize my Mac clipboard when I want to paste something to the public ChatGPT, company Slack, private notes, etc. I ran it through itself before pasting it here, for example. anonymizeclipboard() { my_user_id=xxxx account_ids="1234567890|1234567890" #regex corp_words="xxxx|xxxx|xxxx|xxxx|xxxx" #regex project_names="xxxx|xxxx|xxxx|xxxx|xxxx" # regex pii="xxxx|xxxx|xxxx|xxxx|xxxx|xxxx" # regex hostnames="xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx|xxxx" # regex # anonymize IPs pbpaste | sed -E -e 's/([0-9]{1,3})\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/\1.x.x.x/g' \ -e "s/(${corp_words}|${project_names}|${my_user_id}|${pii}|${hostnames})/xxxx/g" -e "s/(${account_ids})/1234567890/g" | pbcopy pbpaste } alias anon=anonymizeclipboard It prints the new clipboard to stdout so you can inspect what you'll be pasting for anything it missed.
- banku_brougham 1y agobrilliant! this happens all the time and I never found a convenient way to manage
- xwowsersx 1y agoha! alias vz="vim ~/.zshrc && . ~.zshrc" is brilliant. Editing zshrc and sourcing is something I do pretty often. Never thought to alias
- 1718627440 1y agoWhat's the difference between 'source' and '.' ?
- dbalatero 1y agonothing afaict
- iguessthislldo 1y ago
- amterp 1y agoLove this, lots of great ideas I'll be stealing :) Folks interested in scripting like this might like this tool I'm working on https://github.com/amterp/rad https://github.com/amterp/rad Rad is built specifically for writing CLI scripts and is perfect for these sorts of small to medium scripts, takes a declarative approach to script arguments, and has first-class shell command integration. I basically don't write scripts in anything else anymore.
- andai 1y agoalias mpa='mpv --no-video' mpa [youtube_url] I use this to listen to music / lectures in the terminal. I think it needs yt-dlp installed — and reasonably up to date, since YouTube keeps breaking yt-dlp... but the updates keep fixing it :)
- andai 1y agoOn the subject of yt-dlp, I use it to get (timestamped) transcripts from YouTube, to shove into LLMs for summaries. ytsub() { yt-dlp \ --write-sub \ --write-auto-sub \ --sub-lang "en.*" \ --skip-download \ "$1" && vtt2txt } ytsub [youtube_url] Where vtt2txt is a python script — slightly too long to paste here — which strips out the subtitle formatting, leaving a (mostly) human readable transcript.
- Noumenon72 1y ago> ocr my_image.png extracts text from an image and prints it to stdout. It only works on macOS The Mac Shortcut at https://github.com/e-kotov/macos-shortcuts https://github.com/e-kotov/macos-shortcuts lets you select a particular area of the screen (as with Cmd-Shift-4) and copies the text out of that, allowing you to copy exactly the text you need from anywhere on your screen with one keyboard shortcut. Great for popups with unselectable text, and copying error messages from coworkers' screenshares.
- 0cf8612b2e1e 1y agoI have a Linux equivalent that uses maim to select a region and then tesseract to do the OCR.
- andai 1y agoI use these two all the time to encode and cut mp4s. The flags are for maximum compatibility (e.g. without them, some MP4s don't play in WhatsApp, or Discord on mobile, or whatever.) ffmp4() { input_file="$1" output_file="${input_file%.*}_sd.mp4" ffmpeg -i "$input_file" -c:v libx264 -crf 33 -profile:v baseline -level 3.0 -pix_fmt yuv420p -movflags faststart "$output_file" echo "Compressed video saved as: $output_file" } ffmp4 foo.webm -> foo_sd.mp4 fftime() { input_file="$1" output_file="${input_file%.*}_cut.mp4" ffmpeg -i "$input_file" -c copy -ss "$2" -to "$3" "$output_file" echo "Cut video saved as: $output_file" } fftime foo.mp4 01:30 01:45 -> foo_cut.mp4 Note, fftime copies the audio and video data without re-encoding, which can be a little janky, but often works fine, and can be much (100x) faster on large files. To re-encode just remove "-c copy"
- chamomeal 1y agoI started writing way more utility scripts when I found babashka. Magic of clojure, instant startup, easy to shell out to any other command, tons of useful built in stuff, developing with the REPL. It’s just a good time!!
- banku_brougham 1y agothis is really great. at some point i gavenup on being more efficient on the terminal, but many pain points are solved by your work
- hiq 1y agoI've started using snippets for code reviews, where I find myself making the same comments (for different colleagues) regularly. I have a keyboard shortcut opening a fuzzy search to find the entry in a single text file. That saves a lot of time. As an aside, I find most of these commands very long. I tend to use very short aliases, ideally 2 characters. I'm assuming the author uses tab most of the time, if the prefixes don't overlap beyond 3 characters it's not that bad, and maybe the history is more readable.
- haskellshill 1y ago> `nato bar` returns Bravo Alfa Romeo. I use this most often when talking to customer service and need to read out a long alphanumeric string, which has only happened a couple of times in my whole life. But it’s sometimes useful! Even more useful is just learning the ICAO Spelling Alphabet (aka NATO Phonetic Alphabet, of which it is neither). It takes like an afternoon and is useful in many situations, even if the receiver does not know it.
- shellfishgene 1y agoSome time ago I tried to tell my email address to someone in Japan over the phone who did not speak English very well. It turned out to be basically impossible. I realized later one could probably come up with a phonetic alphabet of English words most Japanese know!
- indigodaddy 1y agoNot really a one liner but this comes in handy for quick dns on multiple hostnames: https://gist.github.com/jgbrwn/7dd4b262c544f750cb0291161b2ecd7e https://gist.github.com/jgbrwn/7dd4b262c544f750cb0291161b2ec... (actually avoids having to do a one liner like: for h in {1..5}; do dig +short A mail”${h}”.domain.com @1.1.1.1 ) Hmm speaking of which I need to add in support for using a specific DNS server
- briansm 1y agoUsing 'copy' as a clipboard script tells me OP never lived through the DOS era I guess... Used to drive me mad switching between 'cp' in UNIX and 'copy' in DOS. (Same with the whole slash vs backslash mess.)
- exasperaited 1y agoThe "scripts" I use the most that I am most happy with are a set of Vagrant tools that manage initialising different kinds of application environments with an apt cache on the host. Also .ssh/config includes to make it as easy as possible to work with them from VSCode. I set this stuff up so long ago I sort of forgot that I did it at all; it's like a standard feature. I have to remember I did it.
- abetusk 1y agoI'm kicking myself for not thinking of the `nato` script. I tend to try to not get too used to custom "helper" scripts because I become incapacitated when working in other systems. Nevertheless, I really appreciate all these scripts if nothing else than to see what patterns other programmers pick up. My only addition is a small `tplate` script that creates HTML, C, C++, Makefile, etc. "template" files to start a project. Kind of like a "wizard setup". e.g. $ tplate c #include <stdio.h> #include <stdlib.h> int main(int argc, char **argv) { } And of course, three scripts `:q`, `:w` and `:wq` that get used surprisingly often: $ cat :q #!/bin/bash echo "you're not in vim"
- arjie 1y agoA few I use are: #!/usr/bin/env bash # ~/bin/,dehex echo "$1" | xxd -r -p and #!/usr/bin/env bash # ~/bin/,ht highlight() { # Foreground: # 30:black, 31:red, 32:green, 33:yellow, 34:blue, 35:magenta, 36:cyan # Background: # 40:black, 41:red, 42:green, 43:yellow, 44:blue, 45:magenta, 46:cyan escape=$(printf '\033') sed "s,$2,${escape}[$1m&${escape}[0m,g" } if [[ $# == 1 ]]; then highlight 31 $1 elif [[ $# == 2 ]]; then highlight 31 $1 | highlight 32 $2 elif [[ $# == 3 ]]; then highlight 31 $1 | highlight 32 $2 | highlight 35 $3 elif [[ $# == 4 ]]; then highlight 31 $1 | highlight 32 $2 | highlight 35 $3 | highlight 36 $4 fi I also use the comma-command pattern where I prefix my personal scripts with a `,` which allows me to cycle between them fast etc. One thing I have found that's worth it is periodically running an aggregation on one's history and purging old ones that I don't use.
- blackhaj7 1y agoLove this. Gunna use plenty of these
- desireco42 1y agoI had youtube and serveit and some others, but pasta is really good, thanks!
- janpmz 1y agoLast month I saw a tweet how to serve files using python3 -m http.server 1337 Then I turned it into an alias, called it "serveit" and tweeted about it. And now I see it as a bash script, made a little bit more robust in case python is not installed :)
- zeckalpha 1y agoA couple more standard approaches with fewer chars: jsonformat -> jq running -> pgrep
- sdovan1 1y agoI have three different way to open file with vim: v: vim (or neovim, in my case) vv: search/preview and open file by filename vvv: search/preview and open file by its content alias v='nvim' alias vv='f=$(fzf --preview-window "right:50%" --preview "bat --color=always {1}"); test -n "$f" && v "$f"' alias vvv='f=$(rg --line-number --no-heading . | fzf -d: -n 2.. --preview-window "right:50%:+{2}" --preview "bat --color=always --highlight-line {2} {1}"); test -n "$(echo "$f" | cut -d: -f1)" && v "+$(echo "$f" | cut -d: -f2)" "$(echo "$f" | cut -d: -f1)"'
- dcassett 1y agoI find that I like working with the directory stack and having a shortened version of the directory stack in the title bar, e.g. by modifying the stock Debian .bashrc # If this is an xterm set the title to the directory stack case "$TERM" in xterm*|rxvt*) if [ -x ~/bin/shorten-ds.pl ]; then PS1="\[\e]0;\$(dirs -v | ~/bin/shorten-ds.pl)\a\]$PS1" else PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1" fi ;; \*) ;; esac The script shorten_ds.pl takes e.g. 0 /var/log/apt 1 ~/Downloads 2 ~ and shortens it to: 0:apt 1:Downloads 2:~ #!/usr/bin/perl -w use strict; my @lines; while (<>) { chomp; s%^ (\d+) %$1:%; s%:.*/([^/]+)$%:$1%; push @lines, $_ } print join ' ', @lines; That coupled with functions that take 'u 2' as shorthand for 'pushd +2' and 'o 2' for 'popd +2' make for easy manipulation of the directory stack: u() { if [[ $1 =~ ^[0-9]+$ ]]; then pushd "+$1" else pushd "$@" fi } o() { if [[ $1 =~ ^[0-9]+$ ]]; then popd "+$1" else popd "$@" # lazy way to cause an error fi }
- 0xbadcafebee 1y agoThe scripts from my junk drawer (https://github.com/peterwwillis/junkdrawer https://github.com/peterwwillis/junkdrawer) I use every day are 'kd' and 'gw', which use the Unix dialog command to provide an easy terminal UI for Kubectl and Git Worktrees (respectively)... I probably save 15+ minutes a day just flitting around in those UIs. The rest of the scripts I use for random things; tasks in AWS/Git/etc I can never remember, Terraform module refactoring, Bitbucket/GitHub user management, Docker shortcuts, random password generation, mirroring websites with Wget, finding duplicate files, etc.
- blackhaj7 1y agoDoes anyone have links to other awesome articles like this?
- natch 1y agoAlso this thread and the original article it’s about: https://news.ycombinator.com/item?id=42057431 https://news.ycombinator.com/item?id=42057431
- natch 1y agoThis thread was good: https://news.ycombinator.com/item?id=31928736 https://news.ycombinator.com/item?id=31928736
- blackhaj7 1y agoThese are superb! Thanks for sharing
- senderista 1y agofish abbreviations >> bash aliases
- ttflee 1y ago`perldoc perlrun`
- czertyaka 1y agoSome of these, especially text processing, is already built-in Nushell.
- hshdhdhehd 1y agoThese arent bad but much better if they were all flags to the cat command. E.g. cat --copy
- _gmkt 1y agoThank you, I also stopped using aliases and have everything as scripts in my ~/bin
- deleted 1y ago[deleted]
- merksoftworks 1y agoin oh-my-zsh you can use `take` to do what mkcd does.
- kwar13 1y agothat was beautiful to read. command line ftw!
- teo_zero 1y agoPlease note that 'each' is fundamentally different from 'xargs'. echo 1 2 3 | each "rm {}" is the same as rm 1 rm 2 rm 3 while echo 1 2 3 | xargs rm is the same as rm 1 2 3 I would rather say that 'each' replaces (certain uses of) 'for': for i in 1 2 3; do rm $i; done
- jgtrosh 1y agoIt's equivalent to xargs -I {} rm {} -I replace-str Replace occurrences of replace-str in the initial-arguments with names read from standard input. Also, unquoted blanks do not terminate input items; instead the separator is the newline character. Implies -x and -L 1.
- WA 1y agoOne script I use quite often: function unix() { if [ $# -gt 0 ]; then echo "Arg: $(date -r "$1")" fi echo "Now: $(date) - $(date +%s)" } Prints the current date as UNIX timestamp. If you provide a UNIX timestamp as arg, it prints the arg as human readable date.
- derintegrative 1y agoSimilarly I have for Linux epoch () { if [[ -z "${1:-}" ]] then date +'%s' else date --date="@${1}" fi } % epoch 1761245789 % epoch 1761245789 Thu Oct 23 11:56:29 PDT 2025
- cool-RR 1y agoThe most useful script I wrote is one I call `posh`. It shorten a file path by using environment variables. Example: $ posh /home/ramrachum/Dropbox/notes.txt $DX/notes.txt Of course, it only becomes useful when you define a bunch of environment variables for the paths that you use often. I use this a lot in all of my scripts. Basically whenever any of my script prints a path, it passes it through `posh`.
- oneeyedpigeon 1y agoI'd love to see this script. Does it use `env` and strip out things like PWD?
- cool-RR 1y agoI wrote it in a way that's too intertwined with my other shit to be shareable with people, but honestly you can copy-paste my comment to your friendly neighborhood LLM and you'll get something decent. Indeed it uses `env`.
- oneeyedpigeon 1y agoUnderstood. I'd rather write it myself from scratch than use an LLM; confirmation of the general process should be enough, I hope!
- PUSH_AX 1y agoMkdir then cd into it, I just use ‘take’? Maybe this isn’t available by default everywhere?
- alex_smart 1y agoIt's an omz thing.
- internet_points 1y agoWith `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 < file.txt # indent for markdown: $ clip|sed 's/^/ /'|clip
- deleted 1y ago[deleted]
- spiffyk 1y ago> url "$my_url" parses a URL into its parts. I use this about once a month to pull data out of a URL, often because I don’t want to click a nasty tracking link. This sounds pretty useful! Coincidentally, I have recently learned that Daniel Stenberg et al (of cURL fame) wrote trurl[1], a libcurl-based CLI tool for URL parsing. Its `--json` option seems to yield similar results as TFA's url, if slightly less concise because of the JSON encoding. The advantage is that recent releases of common Linux distros seem to include trurl in their repos[2]. [1]: https://curl.se/trurl/ https://curl.se/trurl/ [2]: https://pkgs.org/search/?q=trurl https://pkgs.org/search/?q=trurl
- liqilin1567 1y agoOne of my biggest headaches is stripping specific number of bytes from the head or tail of a binary file. and I couldn't find any built-in tool for that, so I wrote one in C++.
- rkeene2 1y agoLast X bytes: dd bs=1 skip=X First X bytes: dd bs=X count=1
- liqilin1567 1y agoThanks, there were few errors after testing. 1. stripping fist X bytes: dd bs=1 skip=X 2. stripping last X bytes: truncate -s -X
- internet_points 1y ago`line 10` can be written as `sed -n 10p` (instead of head+tail)
- lolive 1y agoMy most important script has been to remap CapsLock as a kind of custom Meta key, that transforms (when pressed) the Space into Return, hjkl into arrows, io into PgUp/PgDn, and 1-9 into function keys. Now I have a 60% keyboard that takes 0 space on my desk. And I am reaaaally happy with this setup. [that, plus LinkHint plugin for Firefox, and i3 for WM is my way to go for a better life]
- a_e_k 1y agoI like the NATO one. It occurred to me that it would be more useful to me in Emacs, and that might make a fun little exercise. And that's how I discovered `M-x nato-region` was already a thing.
- botverse 1y agoI did something similar with copy until I found this which works across remote terminals too: `alias clip="base64 | xargs -0 printf '\e]52;c;%s\007'"` It just sends it to the client’s terminal clipboard. `cat thing.txt | clip`
- aktau 1y agoI have a bunch, but one that I rarely see mentioned but use all the time is memo(1) (https://github.com/aktau/dotfiles/blob/master/bin/memo https://github.com/aktau/dotfiles/blob/master/bin/memo). It memoizes the command passed to it. $ memo curl https://some-expensive.com/api/call | jq . | awk '...' Manually clearing it (for example if I know the underlying data has changed: $ memo -c curl https://some-expensive.com/api/call In-pipeline memoization (includes the input in the hash of the lookup): $ cat input.txt | memo -s expensive-processor | awk '...' This allows me to rapidly iterate on shell pipelines. The main goal is to minimize my development latency, but it also has positive effects on dependencies (avoiding redundant RPC calls). The classic way of doing this is storing something in temporary files: $ curl https://some-expensive.com/api/call > tmpfile $ cat tmpfile | jq . | awk '...' But I find this awkward, and makes it harder than necessary to experiment with the expensive command itself. $ memo curl https://some-expensive.com/api/call | jq . | awk '...' $ memo curl --data "param1=value1" https://some-expennsive.com/api/call | jq . | awk '...' Both of those will run curl once. NOTE: Currently environment variables are not taken into account when hashing.
- gavinray 1y ago15 years of Linux and I learn something new all the time...
- mlrtime 1y agoIts why I keep coming back, now how do I remember to use this and not go back to using tmpfiles :)
- divan 1y agoI use Warp terminal for couple of years, and recently they embeeded AI into it. At first I was irritated, disabled it, but AI Agent is built in as an optional mode (Cmd-I to toggle). And I found myself using it more and more often for commands that I have no capacity or will to remember or dig through the man pages (from "figure out my IP address on wifi interface" to "make ffmpeg do this or that"). It's fast and can iterate over own errors, and now I can't resist using it regularly. Removes the need for "tools to memorize commands" entirely.
- internet_points 1y agoon my ubuntu, `date -I` does iso dates Also re: alphabet $ echo {a..z} a b c d e f g h i j k l m n o p q r s t u v w x y z
- oneeyedpigeon 1y agodate -I even works on macOS, which I was pleasantly surprised by! If you want the exact alphabet behaviour as the OP: $ echo {a..z} $'\n' {A..Z} | tr -d ' '
- panki27 1y agoMy most used function is probably the one I use to find the most recent files: lt () { ls --color=always -lt ${1} | head }
- apricot13 1y agoand here's me still ctrl+r-ing for my commonly used methods
- dbalatero 1y agohopefully with fzf and not with the built in ctrl r
- sitebolts 1y agoHere are some snippets that we've compiled over time: https://snhps.com https://snhps.com They're not all necessarily the most efficient/proper way to accomplish a task, but they're nice to have on hand and be able to quickly share. Admittedly, their usefulness has been diminished a bit since the rise of LLMs, but they still come in handy from time to time.
- elric 1y agoI've written on this before, but I have an extensive collection of "at" scripts. This started 25+ years ago when I dragged a PC tower running BSD to a friend's house, and their network differed from mine. So I wrote an @friend script which did a bunch of ifconfig foo. Over time that's grown to an @foo script for every project I work on, every place I frequent that has some kind of specific setup. They are prefixed with an @ because that only rarely conflicts with anything, and tab-complete helps me remember the less frequently used ones. The @project scripts setup the whole environment, alias the appropriate build tools and versions of those tools, prepare the correct IDE config if needed, drop me in the project's directory, etc. Some start a VPN connection because some of my clients only have git access over VPN etc. Because I've worked on many things over many years, most of these scripts also output some "help" output so I can remember how shit works for a given project. Here's an example: # @foo PROJECT FOO ----------- VPN Connection: active, split tunnel Commands: tests: mvn clean verify -P local_tests build all components: buildall Tools: java version: 17.0.16-tem maven version: 3.9.11 Edit: a word on aliases, I frequently alias tools like maven or ansible to include config files that are specific to that project. That way I can have a .m2 folder for every project that doesn't get polluted by other projects, I don't have to remember to tell ansible which inventory file to use, etc. I'm lazy and my memory is for shit.
- blixt 1y agoSlightly related but mise, a tool you can use instead of eg make, has “on enter directory” hooks that can reconfigure your system quite a bit whenever you enter the project directory in the terminal. Initially I was horrified by this idea but I have to admit it’s been quite nice to enter into a directory and everything is set up just right, also for new people joining. It has built in version management of just about every command line tool you could imagine, so that an entire team can be on a consistent setup of Python, Node, Go, etc.
- nullwarp 1y agoThis is very useful to me and I had no idea, thanks for pointing that feature out!
- jimmySixDOF 1y agoI had my hopes on this project RawDog using local smol sized LLMs but it hasn't been updated in a while. I feel like all this should be running easily in the background nowadays. https://github.com/AbanteAI/rawdog https://github.com/AbanteAI/rawdog
- duncangh 1y ago4:20 PM - nice
- jwsteigerwalt 1y ago17 years ago I wrote a short VBA macro that takes the high life’s range of cells, concatenates the values into a comma separated list, then opens the list in notepad for easy copy and further use. I can’t begin to count the number of executions by myself and those i have shared it with.
- bemmu 1y agoThe one I use the most is "cdn". It cds to the newest subdirectory. So if you're in your projects folder and want to keep working on your latest project, I just type "cdn" to go there.
- progforlyfe 1y agoabsolutely love these time savers!!
- linsomniac 1y agoThe Gen AI tooling is exceptionally good at doing these sorts of things, and way more than just "mkdir $1 && cd $1". For example: I have used it to build an "escmd" tool for interacting with Elasticsearch. It makes the available commands much more discoverable, the output it formats in tables, and gets rid of sending JSON to a curl command. A variety of small tools that interact with Jira (list my tickets, show tickets that are tagged as needing ops interaction in the current release). A tool to interact with our docker registry to list available tags and to modify tags, including colorizing them based on the sha hash of the image so it's obvious which ones are the same. We manage docker container deploys based on tags so if we "cptag stg prod" on a project, that releases the staging artifact to production, but we also tag them by build date and git commit hash, so we're often working with 5-7 tags. Script to send a "Software has successfully been released" message via gmail from the command-line. A program to "waituntil" a certain time to run a command: "waituntil 20:00 && run_release", with nice display of a countdown. I have a problem with working on too many things at once and then committing unrelated things tagged with a particular Jira case. So I had it write me a commit program that lists my tickets, shows the changed files, and lets me select which ones go with that ticket. All these are things I could have built before, but would have taken me hours each. With the GenAI, they take 5-15 minutes of my attention to build something like this. And Gen AI seems really, really great at building these small, independent tools.
- brainzap 1y agoMy most used automation copies a file with rclone to backblaze blob storage, and puts the link into the clipboard. (for sharing memes) and alias debian="docker run -it --rm -v $(pwd):/mnt/host -w /mnt/host --name debug-debian debian"
- encom 1y agoInteresting, but none of the links are working... codeberg.org isn't responding, it just spins forever.
- hughdbrown 1y agoThis is really interesting, but I need the highlights reel. So I need a script to summarize Hacker News pages and/or arbitrary web pages. Maybe that's what I want for getting the juice out of Medium articles.
- greenpizza13 1y agoFor tempe, recommend changing "cd" to "push" do you can "popd" as soon as you're done.
- cshores 1y agoI have a script called catfiles that I store in ~/.local/bin that recursively dumps every source file with an associated file header so I can paste the resulting blob in to Gemini and ChatGPT in order to have a conversation about the changes I would like to make before I send off the resulting prompt to Gemini Code Assist. Heres my script if anyone is interested in as I find it to be incredibly useful. find . -type f \( -name ".tf" -o -name ".tfvars" -o -name ".json" -o -name ".hcl" -o -name ".sh" -o -name ".tpl" -o -name ".yml" -o -name ".yaml" -o -name ".py" -o -name ".md" \) -exec sh -c 'for f; do echo "### FILE: $f ###"; cat "$f"; echo; done' sh {} +
- GNOMES 1y agoI use my "dc" command to reverse "cd" frequently https://gist.github.com/GNOMES/6bf65926648e260d8023aebb9ede9573 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 for speed.
- rkomorn 1y agoThat's pretty neat. Nice.
- ratrocket 1y agoHas "dc" the calculator fallen this far out of favor?! :) > dc is the oldest surviving Unix language program. https://en.wikipedia.org/wiki/Dc_%28computer_program%29 https://en.wikipedia.org/wiki/Dc_%28computer_program%29 I used "dc" (the calculator) just earlier this week. Kids these days? :)
- hyperman1 1y agoI have a script/alias,named p, that allows me to task switch. It takes an issue and maybe an argument, and does a bunch of things if they make sense in context. It has grown over the years. So 'p ISSUE-123' : * creates a folder issues/ISSUE-123 for work files, containing links to a backed up folder and the project repository . The shell is cd'd to it * The repo might get a new branch with the issue name. * An IDE might start containing the project. * The browsers home button brings you to a page with all kinds of relevant links:. The issue tracker, the CI, all kinds of test pages, etc... * The open/save dialogs for every program gets a shortcut named'issue' * A note is made in a log that allows me to do time tracking at the end if the week. * A commit message template with the issue is created.
- nullgeo 1y agoOne I use a lot is kp, it kills a process listening to a particular TCP port. kp () { if [ -z "$1" ] then echo "Usage: kp <port>" return 1 fi lsof -nP -iTCP:"$1" -sTCP:LISTEN | awk 'NR>1 {print $2}' | xargs kill -9 }
- frodo8sam 1y agoI have these kind of scripts live as functions in my .bashrc, kind of a noob, is there a reason beyond convension to store them individually in bin?
- vilhelmen 1y agoSomething I've long appreciated is a little Perl script to compute statistics on piped in numbers, I find it great for getting quick summaries from report CSVs. #!/usr/bin/perl # http://stackoverflow.com/a/9790056 use List::Util qw(max min sum); @a=(); while(<>){ $sqsum+=$_*$_; push(@a,$_) }; $n=@a; $s=sum(@a); $a=$s/@a; $m=max(@a); $mm=min(@a); $std=sqrt($sqsum/$n-($s/$n)*($s/$n)); $mid=int @a/2; @srtd=sort @a; if(@a%2){ $med=$srtd[$mid]; }else{ $med=($srtd[$mid-1]+$srtd[$mid])/2; }; print "records:$n\nsum:$s\navg:$a\nstd:$std\nmed:$med\max:$m\nmin:$mm";
- 1vuio0pswjnm7 1y agohttps://codeberg.org/EvanHahn/dotfiles/raw/commit/843b9ee13d949d346a4a73ccee2a99351aed285b/home/bin/bin/line https://codeberg.org/EvanHahn/dotfiles/raw/commit/843b9ee13d... This can be replaced with sed -n $1p\;$1q Test it versus head -$1|tail -1
- yellowapple 1y agoLove it! I'll absolutely be borrowing some of these :) On every machine of mine I tend to accumulate a bunch of random little scripts along these lines in my ~/.local/bin, but I never seem to get around to actually putting them anywhere. Trying to knock that habit by putting any new such scripts in a “snippets” repo (https://fsl.yellowapple.us/snippets https://fsl.yellowapple.us/snippets); ain't a whole lot in there yet, but hopefully that starts to change over time.
- omnster 1y agoRegarding the `timer` script, it appears to block the shell. A way to avoid this would be to spawn a subshell for the sleep command like this: `( sleep "$1" && notify ... ) &`
- akullpp 1y agoA lot can be done with just aliasing to the right tools: alias 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'