Merge pull request #888 from equt/master

Add support for XDG specifications
This commit is contained in:
罗泽轩 2020-11-14 10:17:53 +08:00 committed by GitHub
commit 05ce91fb9e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 6 deletions

View file

@ -11,19 +11,23 @@ function show_contents {
fi
}
function global_ignore() {
git config --global core.excludesfile || echo "$XDG_CONFIG_HOME/git/ignore" || echo "$HOME/.config/git/ignore"
}
function show_global {
show_contents Global `git config --global core.excludesfile`
show_contents Global "$(global_ignore)"
}
function add_global {
local global_gitignore=$(git config --global core.excludesfile)
local global_gitignore="$(global_ignore)"
if [ -z "$global_gitignore" ]; then
echo "Can't find global .gitignore."
echo ""
echo "Use 'git config --global --add core.excludesfile ~/.gitignore-global' to set the path to your global gitignore file to '~/.gitignore-global'."
echo ""
else
add_patterns `git config --global core.excludesfile` "$@"
add_patterns "$global_gitignore" "$@"
fi
}

View file

@ -2,9 +2,13 @@
gitignore_io_url="https://www.gitignore.io/api/"
default_path="$HOME/.gi_list"
if [[ -n "$XDG_CACHE_HOME" ]]; then
default_path="$XDG_CACHE_HOME/git-extras/gi_list"
mkdir -p "$XDG_CACHE_HOME/git-extras"
fi
update_gi_list() {
curl -L -s "${gitignore_io_url}/list" > ~/.gi_list
curl -L -s "${gitignore_io_url}/list" > "$default_path"
}
print_in_alphabetical_order() {
@ -73,8 +77,8 @@ show_usage() {
echo " [-l|--list-in-table] Print available types in table format"
echo " [-L|--list-alphabetically] Print available types in alphabetical order "
echo " [-s|--search] <word> Search word in available types"
echo " [-t|--show-update-time] Show the last modified time of ~/.gi_list (where the list of available types is stored)"
echo " [-u|--update-list] Update ~/.gi_list"
echo " [-t|--show-update-time] Show the last modified time of $default_path (where the list of available types is stored)"
echo " [-u|--update-list] Update $default_path"
}