title:Fish Magic
posted:2024-02-01
tags:["all", "fish", "linux", "shell"]


Technology keeps moving but this post has not.

What you're about to read hasn't been updated in more than a year. The information may be out of date. Let me know if you see anything that needs fixing.

I've been using (and loving) fish shell↗ for a little while now, and I still frequently discover clever behaviors that make my CLI tasks more enjoyable.

Today's discovery: fish will automatically escape single quotes when pasting text↗ into the command line. 

If it outputs to the commandline, it will automatically escape the output if the cursor is currently inside single-quotes so it is suitable for single-quotes (meaning it escapes ' and \\).

So if I work up an ugly one-liner for determining the IP address of whatever interface is attached to the default route:

ip addr show $(ip route | grep default | awk '{print $5}') | grep 'inet ' | awk '{print $2}' | cut -d/ -f1

And then decide I'd like to make that into a reusable alias↗, I can copy that line and paste it in after

alias get_ip='

and fish will automagically take care of escaping all those troublesome single quotes

alias get_ip='ip addr show $(ip route | grep default | awk '{print $5}') | grep 'inet ' | awk '{print $2}' | cut -d/ -f1'

Neat!

Command-line interface displaying text commands and outputs for IP address configurations.


📧 Reply by email

runtimeterror 


 John Wq