DEV Community

Discussion on: What are your preferred bash aliases?

Collapse
 
thefluxapex profile image
Ian Pride

I pretty much skip aliases and only make functions most of the time. I do have exceptions, but for the most part I have a "master" .bash_funcs config that I use on most of my machines that I have been building/editing/refactoring for MANY years that has all my favorite stuff in it.
Even for non-args stuff.
It's really hard to pick; so much of it saves time or keystrokes and I find most of them essential.
If you consider small one liner or simple functions as aliases then a few I love are:

Alternate touch

Use null to zero/create a file.

function touchf(){ [[ $# -gt 0 ]] && cat /dev/null > "$*"; }

Get cursor coordinates with xdotool

function getmousecoords(){
        xdotool getmouselocation|awk \
                '{sub(/^x:/,"",$1);\
                sub(/^y:/,"",$2);\
                print $1 " " $2}'
}

Use realpath with Fuzzy Finder to get the a full path (alternate method)

function realfzf() { find "$(realpath $*)" -iname "*" | fzf; }

I have a much smaller alias file (< 10 old aliases that plan to functionize at some point lol)

Always force make parent directories if they don't exist

alias mkdir='mkdir -p'

'ls' with no color for various reasons

I usually either have 'ls' aliased to default list with colors (I think it's preset in some envs) and this overrides it when I need output without color

alias lsn='ls --color=never'

And one for fun :D Show time in the console but in alternating colors.

I have plans to rewrite this using '\r' instead of clear

alias colortime='while :; do for i in {{30..37},{90..97}}; do echo -en "\e[0;${i}m$(date +%r)\e[0m ";sleep 1;clear; 
done; done'

I have so many functions I love I could just keep going, but my main function file is around 8500 lines so I won't do that to you lol.

Collapse
 
wulymammoth profile image
David • Edited

Do you have these functions in a public repository? I'd love to check them out.

I've a handful of functions that I rarely use anymore like one that took an argument like docs mdn that would open my browser to Mozilla's documentation and docs til that would open my TIL (today I learned) repository on GitHub with rendered markdown.

I've only a handful of aliases as well allowing me to jump around (change dirs) into personal or work, and my dotfiles along with a couple more just masking other commands, like alias vim=nvim since I use Neovim and alias make=mmake (Modern Make)

I keep a long history and much prefer using reverse-i-search to dig up a command that I use somewhat frequently

Collapse
 
thefluxapex profile image
Ian Pride • Edited

I do actually plan on a Shell section on my main misc programming GitHub IO site that has lots of it organized, but it's still "under construction" lol. In the next couple of days I'll make a copy and clean lots of crap and redundancy out of it and put it up in a temp repo and post it back here.

I use history/fzf, but I have extra laptops that I'm always testing distros on and so I always just import my dots, but yeah I'm constantly doing Ctrl+r; FZF is just amazing.

Thread Thread
 
wulymammoth profile image
David

Don’t have to mention fzf twice. It’s a must have both in my shell and Vim coupled with ripgrep. Ah! You’re a distro junkie! Haven’t settled on Arch or Gentoo?

Thread Thread
 
thefluxapex profile image
Ian Pride

I try anything out, but stick to Debian based. Ubuntu on main/family member machines usually. I do have a soft spot for Bodhi with Enlightenment.

Collapse
 
moopet profile image
Ben Sinclair • Edited

Use null to zero/create a file

I'd do :> foo to do this (well, I use :>| foo because I have noclobber set, but...)

As for needing to output ls without colour, I think color=auto works for most colour-aware commands in that you get colours, but they're suppressed if the output's to a pipe. That should cover most cases?

Collapse
 
thefluxapex profile image
Ian Pride

The reason why I originally created that alias is because at some point, for whatever glitched reason, I couldn't force colors off and that was the only way I could force it off. Don't remember exactly what it was; it's been a few years and my memory has been slipping lately.