Share an Elixir or dev-env tip a day

..or as and when you can think of one :icon_cool:

This thread my also be of interest: What took you way too long to figure out? :003:

1 Like

I accidentally pasted my banking password into Terminal, so wanted to delete it to be on the safe side!

# close the app, then: 
rm ~/.zsh_history
rm -rf ~/.zsh_sessions
3 Likes

Why not edit the file to remove that line?

I use my shell history constantly, so I’m loathed to blow it away

4 Likes

That’s actually a good idea! :see_no_evil_monkey:

(I wasn’t too bothered on this machine though as I’ve just done a clean install, so there was very little history)

1 Like

(edit: actually the top tips are all things like “new elixir version released (in 2017)!”…)

1 Like
export ERL_AFLAGS='-kernel shell_history enabled  -kernel shell_history_path \".erl.history\"'

The above makes iex sessions to store their history on a per-project basis in project directories. ,gitignore should be also updated to include /.erl.history/.

23 Likes

I have already said it few times in different places, but do yourself a favour, and if you are using Git, then have globally (in ~/.config/git/attributes) or per project (in .gitattributes):

mix.lock merge=binary

This will make conflict resolution of mix.lock much easier.


Explanation

This will tell Git to treat Mix lock file as a binary file when doing merges/rebases. This mean, that if there is a conflict, there will be stop (so you need to resolve such conflict), but it will leave file as is (with no conflict markers). This makes my life much easier, as you can then just do mix deps.update --all (as it is most of the time source of such conflicts) and then just git add mix.lock && git rebase --continue.

12 Likes

Talking about git, I like to configure mine based article: How Core Git Developers Configure Git | Butler's Log. It contains some good info and recommendations you can use to improve the git defaults in your dev env.

5 Likes

Thanks for sharing, that was a good read.

2 Likes

This thread is similar in spirit to a thread I made a while back, so I’ll share it here: What took you way too long to figure out?

I was going to put something in there the other day, but never got around to it… and now I forget what it was :frowning:. I remember enough to know it would have fit perfectly here…

Also just wanted to bump the thread. :slight_smile:

1 Like

Added a link to it in the first post :023:

This thread may also be of interest: What took you way too long to figure out? :003:


Kinda off-topic tip… but keep a note book handy/by your bed. Writing things down that come in to your mind just before going to sleep can actually help you sleep - as you’re not worrying about having to remember them! :icon_biggrin:

2 Likes

Another quick tip of something I use frequently in Terminal, is:

open .

Which will open the current directory in Finder.

So if you’re in /Users/Aston/Projects, it will open the Projects folder.

In vim, you can change the current/next search match with cgn. It’s also repeatable with ., and you don’t even need to use n to advance if you know you want to replace the next match.

Bonus tip: * will start a search for the word under the cursor and jump to the next match.

5 Likes

That is why I created GitHub - hauleth/sad.vim: Quick search and replace for Vim, which is a plugin that utilises that functionality to provide repeatable replaces.

2 Likes

One small from me - I’ve added a function in my fish-shell that looks like this:

function dbg
  set test_path $argv[1]
  iex --dbg pry -S mix test $test_path --trace
end

Provided there’s a dbg() macro anywhere in the Elixir code under test, this allows me to enter an interactive debugging session quickly by going from:

mix test test/my_app/permissions/api_test.exs:627

to:

dbg test/my_app/permissions/api_test.exs:627
5 Likes

As per the Finder version, if you’re using WSL: explorer.exe . does the same thing.

1 Like

Dang, can’t believe I never knew this, thanks!

I like to remap * like so:

nnoremap <silent> * :let @/ = '\<' . expand('<cword>') . '\>'<bar>setlocal hlsearch<cr>

This set the search register to the current keyword under the cursor, turns on highlighting for the current buffer, and leaves the cursor in place. This works like an opt-in traces.vim that I find much less jarring. Incidentally, I leave # as-is. I can’t explain why but it’s just what feels right :person_shrugging:

EDIT: I can explain :sweat_smile: It seems most of the time I’m not sure which way I’m looking, so remapping * this way gives me context. If I know for sure I want to go up then # just takes me to the first thing. Sometimes I know that I want to go down which means I have to press *n which is semi-annoying but not the worst.

2 Likes

If you’re ever doing a capture the flag challenge and you have managed to get onto the box, always make sure to check the terminal history. You might find a clue as to what to do next in the puzzle.

1 Like

Now that I know where the file is I have created an alias for it :003:

alias bashhistory="mate ~/.zsh_history"

Something that would be handy is directory specific history - do you (or anyone) know if that’s possible?

I have been using this shell script for years to easily find the latest modified Git branches, specially when dealing with a crazy amount of branches per repo.

~/bin/git-branch-by-commit-date

#!/bin/bash
# Lists Git branches sorted by commit dates in descending order.

# Originally taken from: http://stackoverflow.com/questions/2514172/listing-each-branch-and-its-last-revisions-date-in-git/2514279#2514279

for k in $(git branch | perl -pe s/^..//);
  do echo -e "$(git show --pretty=format:"%Cgreen%ci %Cblue%cr%Creset" "$k" -- | head -n 1)"\\\\t"$k";
done | sort -r

And the output looks like:

❯ git-branch-by-commit-date
2025-11-04 12:31:53 +0100 3 days ago	main
2025-10-30 22:06:07 +0100 7 days ago	chore/remove-br-deprecations
2025-10-30 08:18:13 -0500 7 days ago	chore/update-mix-tasks-new-reserved-app-names
2025-10-29 01:06:47 -0500 9 days ago	feature/mix-new-sample-code
2025-10-08 12:02:21 -0500 4 weeks ago	chore/fix-spdx-summary
…
2025-07-09 23:08:13 -0500 4 months ago	chore/use-commas-in-numbers
2025-05-09 21:01:53 -0500 6 months ago	feature/ci-docs-warnings-as-errors
2025-05-09 21:00:06 -0500 6 months ago	feature/makefile-docs-options
…
2023-05-12 08:43:45 -0500 2 years, 6 months ago	improve-error-message-supervisor-child-spec
2018-12-06 13:07:49 +0100 7 years ago	v1.3
2 Likes