Posts tagged with bash

How to automatically generate a commit message using Claude

by Freek Van der Herten – 5 minute read

For years, my git history contains "wip" commit messages. I don't really often use git history myself, but my colleagues do. And when they're trying to understand a change I made six months ago, "wip" tells them absolutely nothing. Might as well not have commit messages at all.

I knew I should write better commit messages, but the friction was real. Stopping to think about how to summarize my changes felt like it broke my flow. So I kept typing "wip".

Now, I have a bash function in my dotfiles that uses Claude to generate commit messages for me.

Read more

Saying goodbye to WIP commit messages

by Freek Van der Herten – 5 minute read

There are two kinds of developers: those that write commit messages and value a repo's history and those that don't. I'm in the latter camp: most of my commit messages just read "WIP", much to the chagrin of some of my colleagues. I've tried to change my ways, but I just can't get into the habit of writing good commit messages.

But now I have a solution: I use the power of AI to write my commit messages for me. In this blog post, I'll show you how I did it.

Read more

Join thousands of developers

Every two weeks, I share practical tips, tutorials, and behind-the-scenes insights from maintaining 300+ open source packages.

No spam. Unsubscribe anytime. You can also follow me on X.

A bash function to run tests for both PHPUnit and Pest

by Freek Van der Herten – 2 minute read

I've used this little bash alias for many years to quickly run the tests inside of a project.

alias p="vendor/bin/phpunit"

With this alias in place, I can run the tests by typing "p" on the CLI. Nice!

For a long time, everything was great! But then, Pest appeared on the scene. It's an alternative test runner for PHP with a high focus on developer experience.

Read more

Run and stop multiple long-running commands from Bash with a trap

liamhammett.com

Liam Hammett explains how you can use the trap command to stop multiple bash process in one go.

Sometimes when working on a project, I’ll always want to run a handful of commands at the same time, some of which may return when they’re done, others might be long-running, like watchers or services actively exposing ports. This is something that might seem simple to do with a basic Bash script at first, but what if your script has multiple processes running side-by-side and you want to be able to stop them all at once too?

Read more [liamhammett.com]

Easily switch PHP versions in Laravel Valet

by Freek Van der Herten – 2 minute read

Besides enjoying some greenfield work, we often have to work on legacy projects at Spatie too. Sometimes those projects don't run on the latest PHP version. I this blogpost I'd like to show you a way to switch PHP version easily when using Laravel Valet. (I know you could also use Docker or…

Read more

Quickly open a GitHub page from your terminal

At Spatie we use GitHub for both our client projects as our open source code. So in our day to day work we often have to open the browser to view issues of a repo or review pull requests.

Paul Irish, a well known developer and part of the Google Chrome team at Google, made a nice bash script to quickly open up a GitHub page from your terminal. If you're on a path inside a git repo and type "git open" that'll open up the corresponding page on GitHub.

The command also supports, amongst others, repos hosted on GitLab.com and Bitbucket.

https://github.com/paulirish/git-open

Read more

Advancing in the Bash Shell

If you want to learn some neat bash tricks, read this excellent read by Sam Rowe.

If you’ve ever used GNU/Linux, chances are good that you’ve used bash. Some people hold the belief that using a GUI is faster than using a CLI. These people have obviously never seen someone who uses a shell proficiently. In this tutorial, I hope to show you just a few of the amazing features bash provides that will increase your productivity in the shell.

http://samrowe.com/wordpress/advancing-in-the-bash-shell/

Read more

The Bash For Loop, The First Step in Automation on Linux

In a post on his site Mattias Geniar shares how to write for loops in Bash.

Let me first start by saying something embarrassing. For the first 4 or 5 years of my Linux career -- which is nearing 10 years of professional experience -- I never used loops in Bash scripts. Or at the command line.

The thing is, I was a very fast mouse-clicker. And a very fast copy/paster. And a good search & replacer in vim and other text editors. Quite often, that got me to a working solution faster than working out the quirky syntax, testing, bugfixing, ... of loops in Bash.

And, to be completely honest, if you're managing just a couple of servers, I think you can get away with not using loops in Bash. But, once you master it, you'll wonder why you haven't learned Bash for-loops sooner.

https://ma.ttias.be/bash-loop-first-step-automation-linux/

Read more

Recovering from a rm -rf

????

I run a small hosting provider with more or less 1535 customers and I use Ansible to automate some operations to be run on all servers. Last night I accidentally ran, on all servers, a Bash script with a `rm -rf {foo}/{bar}` with those variables undefined due to a bug in the code above this line.

All servers got deleted and the offsite backups too because the remote storage was mounted just before by the same script (that is a backup maintenance script).

http://serverfault.com/questions/769357/recovering-from-a-rm-rf

Read more

Easy file sharing from the command line

Transfer.sh is a free service by Dutchcoders that allows you to easily share files from the command line. Here's an example of how you can use it:

transfer my-favorite-file.txt

The given file will be uploaded to the transfer.sh-servers and the command will respond with a short url linking to that file. Pretty neat!

The only thing you need to do is set up a bash function called "transfer" (you can name it anything you want really).

Don't trust the transfer.sh with your supersecret files? Then you can set up your own server to transfer the files to.

Read more