Skip to content

Commit

Permalink
Support for $XDG_CONFIG_HOME
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasbestle committed Apr 11, 2020
1 parent 59c0c95 commit 5f049e4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ The information below the fancy dynamic ASCII art comes from a modular informati

The `welcome` script from the `bin` directory can be installed anywhere in your `$PATH`. `~/bin` makes sense, but it can be any directory.

### Setup a configuration directory

The configuration of `welcome` can either be stored in `~/.welcome` or in `$XDG_CONFIG_HOME/welcome` (which defaults to `~/.config/welcome`). Please create this directory and place all files from the following steps into it.

### Install figlet, a dependency of welcome

[figlet](http://www.figlet.org) is a command line tool to generate fancy ASCII art from text and is a required depencency of welcome.
Expand All @@ -29,7 +33,7 @@ The `welcome` script from the `bin` directory can be installed anywhere in your
toast arm ftp://ftp.figlet.org/pub/figlet/program/unix/figlet-2.2.5.tar.gz
```

2. Get colossal, a figlet ASCII font that looks great but is not included by default: Download the file [colossal.flf](http://www.figlet.org/fonts/colossal.flf) from the figlet website and place it in `~/.welcome/colossal.flf`.
2. Get colossal, a figlet ASCII font that looks great but is not included by default: Download the file [colossal.flf](http://www.figlet.org/fonts/colossal.flf) from the figlet website and place it in `.welcome/colossal.flf`.

### Create your own information providers

Expand All @@ -39,7 +43,7 @@ The reason welcome is so flexible is the modular information provider system. Th

A summarizer is a function that returns one or more lines of text. Summarizers are expected to always output information and are therefore useful for information like the current date, the system uptime etc.

You can place as many summarizers as you need in `~/.welcome/summarizers`. Each summarizer is a shell script with a specific structure:
You can place as many summarizers as you need in `.welcome/summarizers`. Each summarizer is a shell script with a specific structure:

```bash
function helloWorldSummarizer() {
Expand All @@ -54,17 +58,17 @@ This summarizer will output a simple `Hello: World`.

The order of the summarizers gets defined by the order in the file system. So to force a specific order, simply prepend numbers, like so: `01-helloworld.sh`.

**There is one thing you need to do before this can work: Your summarizers must actually be executable files to make sure only files you wanted to run are run, so please set `chmod +x ~/.welcome/summarizers/*`**.
**There is one thing you need to do before this can work: Your summarizers must actually be executable files to make sure only files you wanted to run are run, so please set `chmod +x .welcome/summarizers/*`**.

#### Warners

Warners are the second kind of information provider. The difference to summarizers is that a warner does not have to output anything. They are useful for information that is only relevant in specific situations (for example when a package update is available like in the screenshot above).

You can place as many warners as you need in `~/.welcome/warners`. Warners are arbitrary binaries that simply output text.
You can place as many warners as you need in `.welcome/warners`. Warners are arbitrary binaries that simply output text.

The order of the warners also gets defined by the order in the file system. So to force a specific order, simply prepend numbers, like so: `01-helloworld.sh`.

**Same here: Please set `chmod +x ~/.welcome/warners/*` to make sure only files you wanted to run are run**.
**Same here: Please set `chmod +x .welcome/warners/*` to make sure only files you wanted to run are run**.

#### Examples

Expand Down
26 changes: 17 additions & 9 deletions bin/welcome
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,22 @@
########################################################################
# Prints a login welcome message with status information and ASCII art
# This tool relies on a modular information provider setup in ~/.welcome
# See README for detailed information
# or $XDG_CONFIG_HOME/welcome; see README for detailed information
#
# Usage: welcome
########################################################################

# Define indentation
indentation=' '

# Detect configuration path
configPath=${XDG_CONFIG_HOME:-$HOME/.config}
if [[ -d "$configPath/welcome" ]]; then
configPath="$configPath/welcome"
else
configPath="$HOME/.welcome"
fi

# -----------------------------------------
# Check for availability of files and tools

Expand All @@ -22,15 +30,15 @@ if ! command -v figlet &> /dev/null; then
echo -e "\033[31mWelcome anyway. :)\033[0m"
exit 1
fi
if [[ ! -d ~/.welcome ]]; then
echo -e "\033[34m~/.welcome\033[31m does not exist.\033[0m"
if [[ ! -d "$configPath" ]]; then
echo -e "\033[31mCould not find configuration directory.\033[0m"
echo -e "\033[31mPlease follow the installation instructions in \033[34mREADME\033[31m.\033[0m"
echo
echo -e "\033[31mWelcome anyway. :)\033[0m"
exit 1
fi
if [[ ! -f ~/.welcome/colossal.flf ]]; then
echo -e "\033[34m~/.welcome/colossal.flf\033[31m does not exist.\033[0m"
if [[ ! -f "$configPath/colossal.flf" ]]; then
echo -e "\033[34m$configPath/colossal.flf\033[31m does not exist.\033[0m"
echo -e "\033[31mPlease follow the installation instructions in \033[34mREADME\033[31m.\033[0m"
echo
echo -e "\033[31mWelcome anyway. :)\033[0m"
Expand All @@ -56,7 +64,7 @@ function echoPrepare() {
computerName=${HOSTNAME%%.*}

# Generate ASCII art and indent every line of it
ascii=$(figlet -k -f ~/.welcome/colossal.flf -w 150 "$USER@$computerName")
ascii=$(figlet -k -f "$configPath/colossal.flf" -w 150 "$USER@$computerName")
asciiIndented=$(echo "$ascii" | sed "s/^/$indentation/")

# Generate user and hostname string (colored for output, uncolored for length determination)
Expand Down Expand Up @@ -89,7 +97,7 @@ echoPrepare "$indentation$userAndHostnameCentered"
# --------------------
# Load env summarizers

if ls ~/.welcome/summarizers/*.sh &> /dev/null; then
if ls "$configPath/summarizers/"*.sh &> /dev/null; then
echoPrepare

# Store for summarizers
Expand Down Expand Up @@ -120,7 +128,7 @@ if ls ~/.welcome/summarizers/*.sh &> /dev/null; then
}

# Load the summarizer files and let them register themselves
for summarizer in ~/.welcome/summarizers/*.sh; do
for summarizer in "$configPath/summarizers/"*.sh; do
# Check if the file is executable (security check)
if [[ ! -x "$summarizer" ]]; then
continue
Expand Down Expand Up @@ -151,7 +159,7 @@ fi
# Load warners

# Load the warner files
for warner in ~/.welcome/warners/*; do
for warner in "$configPath/warners/"*; do
# Check if the file is executable (security check)
if [[ ! -x "$warner" ]]; then
continue
Expand Down

0 comments on commit 5f049e4

Please sign in to comment.