dt.iki.fi
30.6.2025 sailfish os, linux

Add shell customisations for all users

To add shell customisations for all users, add a file to /etc/profile.d - I named it zzz.sh in the hope it will be sourced last and override some values. It will survive system updates.

# i stands for interactive. If not interactive, bail
[ "$-" != "${-##*i}" ] || return

EDITOR=nano

# simple alias to grep from history
alias hf='history|grep'
# ignore this alias and other extremely common commands
HISTIGNORE="hf *:ll"
HISTSIZE=100000 # the default 1000 is too small
HISTCONTROL=ignoreboth:erasedups

#PS1 defines the regular prompt:
# It is colored red for root, yellow othersise.
# It displays any return value other than `0` in a distinct color.
# It shows user@hostname:/current/working/directory
# Finally, it displays the actual `>` prompt on a new line.
PS1='\[\e[00;35m\]${?#0}\[\e[00;$([ $USER = root ] && echo 31m || echo 33m)\]\u@\h:\w\n\[\e[00;$([ $USER = root ] && echo 31m || echo 33m)\]>\[\e[00m\] '

# Other prompts; rare
PS2='cont> '
PS3='Choice: '
PS4='DEBUG: '

[ -d "$HOME/.local/bin" ] && pathmunge "$HOME/.local/bin"

export PS1 PS2 PS3 PS4 EDITOR HISTIGNORE HISTSIZE HISTCONTROL PATH

alias ll='ls -alFh --group-directories-first --color=auto'

pklist() {
  echo "Use rpm -ql instead"
  pkcon get-files "$@"|tr ';' '\n'|more
}

## Only these last bits might throw errors if you use busybox bash:

shopt -s histappend

# bash completion is installed on SFOS but not enabled by default
for f in /usr/share/bash-completion/completions/* /etc/bash_completion.d/*; do
    . "$f" >/dev/null
done
unset f

This file includes Bashisms. By default, /bin/bash is symlinked to busybox. I recommend actually installing bash for terminals; if not, you might want to remove the last lines.

The pathmunge function should still be defined from /etc/profile.