Ansible role that configures my bash dotfiles and some related scripts
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
taha@asks2 e1db677b0c Function commits() lists latest commit across all git repos 3 months ago
defaults Symlinking (or not) of chepec now handled by user-defined variable 7 months ago
docs Function commits() lists latest commit across all git repos 3 months ago
files Function commits() lists latest commit across all git repos 3 months ago
tasks Improved legibility of code by merging some tasks 5 months ago
templates Created hostinfo scripts for new servers. 8 months ago
.gitignore Configures dotfiles for multiple hosts 9 months ago Added note on gitconfig to README 7 months ago


This Ansible role configures the so-called dotfiles (.bashrc and friends) for the current user (and an optional second user account).


Since git version 2.13 (we are on 2.17 now), we can use conditional include to configure different identities by folder. This could be useful for me.


Some considerations regarding bash history

I started off with these settings in ~/.bashrc, settings which I had used since I moved to Ansible playbook management of my workstation:

# don't put duplicate lines or lines starting with space in the history

# append to the history file, don't overwrite it
shopt -s histappend

# leaving empty means set history to infinite

This has served my well. There was one thing I thought I might improve, and that's sharing of history between concurrent terminals on the same host.

Quite often, I'd move from one open terminal, to another (say when I switched workspaces in i3), and be annoyed that the long command I just typed in the terminal on workspace 1 was not visible in the history of the terminal on workspace 2.

So what I am trying to achieve at the moment, is a shared history across all terminals. So if I run a command in terminal 1, then go to an already opened terminal 2, and press arrow Up, the command I just ran in terminal 1 should show up.

It seems there is a way to achieve this. It does involve redefining PROMPT_COMMAND, which means that we are adding time (albeit slight) to a command that executes after each and every terminal command.

The amount of processing work between each command is proportional to the size of the history file. (comment by Stéphanie Gourichon)

For reference, my .bash_history file on luxor currently has just over 16000 lines (with many hundreds of duplicated lines).

For now, I'm inclined not to care about duplicates in the history file. Perhaps later, I will look into cleaning out duplicate lines using HISTCONTROL=erasedups or similar.

Alright, so I'm going to start by trying a combination of the SE answers/comments and the DO tutorial, like this:

shopt -s histappend
PROMPT_COMMAND="history -a; history -c; history -r; $PROMPT_COMMAND"

Explanation of history flags: -a: append the new history lines (history lines entered since the beginning of the current Bash session) to the history file. -c: Clear the history list. This can be combined with the other options to replace the history list completely. -r: Read the current history file and append its contents to the history list.

Will see how this works.

Well, almost. You have to press Enter (or any key really, the point is you have to refresh the prompt) before the history from the other terminal(s) becomes available in your current terminal.

How to list the top X commands from bash history

Top 100 commands (strips any arguments before counting):

``history | sed "s/^[0-9 ]*//" | sed "s/ *| */\n/g" | awk '{print $1}' | sort | uniq -c | sort -rn | head -n 100

Here's another way, without stripping the arguments before counting:

sort .bash_history | uniq -c | sort -n | tail -n 100

Note that this latter command will likely not be useful at all
if the history file does not contain duplicates.

Question: why does it contain duplicates, isn't `HISTCONTROL=ignoreboth`
supposed to avoid duplicate lines in history?