Skip to content

Commit 5f049e4

Browse files
committed
Support for $XDG_CONFIG_HOME
1 parent 59c0c95 commit 5f049e4

File tree

2 files changed

+26
-14
lines changed

2 files changed

+26
-14
lines changed

README.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ The information below the fancy dynamic ASCII art comes from a modular informati
2020

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

23+
### Setup a configuration directory
24+
25+
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.
26+
2327
### Install figlet, a dependency of welcome
2428

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

32-
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`.
36+
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`.
3337

3438
### Create your own information providers
3539

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

4044
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.
4145

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

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

5559
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`.
5660

57-
**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/*`**.
61+
**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/*`**.
5862

5963
#### Warners
6064

6165
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).
6266

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

6569
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`.
6670

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

6973
#### Examples
7074

bin/welcome

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,22 @@
44
########################################################################
55
# Prints a login welcome message with status information and ASCII art
66
# This tool relies on a modular information provider setup in ~/.welcome
7-
# See README for detailed information
7+
# or $XDG_CONFIG_HOME/welcome; see README for detailed information
88
#
99
# Usage: welcome
1010
########################################################################
1111

1212
# Define indentation
1313
indentation=' '
1414

15+
# Detect configuration path
16+
configPath=${XDG_CONFIG_HOME:-$HOME/.config}
17+
if [[ -d "$configPath/welcome" ]]; then
18+
configPath="$configPath/welcome"
19+
else
20+
configPath="$HOME/.welcome"
21+
fi
22+
1523
# -----------------------------------------
1624
# Check for availability of files and tools
1725

@@ -22,15 +30,15 @@ if ! command -v figlet &> /dev/null; then
2230
echo -e "\033[31mWelcome anyway. :)\033[0m"
2331
exit 1
2432
fi
25-
if [[ ! -d ~/.welcome ]]; then
26-
echo -e "\033[34m~/.welcome\033[31m does not exist.\033[0m"
33+
if [[ ! -d "$configPath" ]]; then
34+
echo -e "\033[31mCould not find configuration directory.\033[0m"
2735
echo -e "\033[31mPlease follow the installation instructions in \033[34mREADME\033[31m.\033[0m"
2836
echo
2937
echo -e "\033[31mWelcome anyway. :)\033[0m"
3038
exit 1
3139
fi
32-
if [[ ! -f ~/.welcome/colossal.flf ]]; then
33-
echo -e "\033[34m~/.welcome/colossal.flf\033[31m does not exist.\033[0m"
40+
if [[ ! -f "$configPath/colossal.flf" ]]; then
41+
echo -e "\033[34m$configPath/colossal.flf\033[31m does not exist.\033[0m"
3442
echo -e "\033[31mPlease follow the installation instructions in \033[34mREADME\033[31m.\033[0m"
3543
echo
3644
echo -e "\033[31mWelcome anyway. :)\033[0m"
@@ -56,7 +64,7 @@ function echoPrepare() {
5664
computerName=${HOSTNAME%%.*}
5765

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

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

92-
if ls ~/.welcome/summarizers/*.sh &> /dev/null; then
100+
if ls "$configPath/summarizers/"*.sh &> /dev/null; then
93101
echoPrepare
94102

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

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

153161
# Load the warner files
154-
for warner in ~/.welcome/warners/*; do
162+
for warner in "$configPath/warners/"*; do
155163
# Check if the file is executable (security check)
156164
if [[ ! -x "$warner" ]]; then
157165
continue

0 commit comments

Comments
 (0)