Skip to content

Commit 05ce91f

Browse files
authored
Merge pull request #888 from equt/master
Add support for XDG specifications
2 parents d2a159e + fca4277 commit 05ce91f

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

bin/git-ignore

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,23 @@ function show_contents {
1111
fi
1212
}
1313

14+
function global_ignore() {
15+
git config --global core.excludesfile || echo "$XDG_CONFIG_HOME/git/ignore" || echo "$HOME/.config/git/ignore"
16+
}
17+
1418
function show_global {
15-
show_contents Global `git config --global core.excludesfile`
19+
show_contents Global "$(global_ignore)"
1620
}
1721

1822
function add_global {
19-
local global_gitignore=$(git config --global core.excludesfile)
23+
local global_gitignore="$(global_ignore)"
2024
if [ -z "$global_gitignore" ]; then
2125
echo "Can't find global .gitignore."
2226
echo ""
2327
echo "Use 'git config --global --add core.excludesfile ~/.gitignore-global' to set the path to your global gitignore file to '~/.gitignore-global'."
2428
echo ""
2529
else
26-
add_patterns `git config --global core.excludesfile` "$@"
30+
add_patterns "$global_gitignore" "$@"
2731
fi
2832
}
2933

bin/git-ignore-io

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22

33
gitignore_io_url="https://www.gitignore.io/api/"
44
default_path="$HOME/.gi_list"
5+
if [[ -n "$XDG_CACHE_HOME" ]]; then
6+
default_path="$XDG_CACHE_HOME/git-extras/gi_list"
7+
mkdir -p "$XDG_CACHE_HOME/git-extras"
8+
fi
59

610
update_gi_list() {
7-
curl -L -s "${gitignore_io_url}/list" > ~/.gi_list
11+
curl -L -s "${gitignore_io_url}/list" > "$default_path"
812
}
913

1014
print_in_alphabetical_order() {
@@ -73,8 +77,8 @@ show_usage() {
7377
echo " [-l|--list-in-table] Print available types in table format"
7478
echo " [-L|--list-alphabetically] Print available types in alphabetical order "
7579
echo " [-s|--search] <word> Search word in available types"
76-
echo " [-t|--show-update-time] Show the last modified time of ~/.gi_list (where the list of available types is stored)"
77-
echo " [-u|--update-list] Update ~/.gi_list"
80+
echo " [-t|--show-update-time] Show the last modified time of $default_path (where the list of available types is stored)"
81+
echo " [-u|--update-list] Update $default_path"
7882
}
7983

8084

0 commit comments

Comments
 (0)