Support for $XDG_CONFIG_HOME

This commit is contained in:
2020-05-30 17:10:25 +02:00
parent 22ada23b8b
commit e9bd0acd5f
9 changed files with 62 additions and 20 deletions
+11 -3
View File
@@ -35,9 +35,17 @@ if ! (mkdir "$project" && mkdir "$project/data" && touch "$project/.project"); t
fi
echo -e " => \033[32mSuccess.\033[0m"
# Add to ~/.projects
echo -e "\033[1mAdding project to \033[34m~/.projects\033[0;1m...\033[0m"
if ! echo "$(readlink -f "$project")" >> "$HOME/.projects"; then
# Determine the path to the projects file
configPath=${XDG_CONFIG_HOME:-$HOME/.config}
if [[ -d "$configPath/projectr" ]]; then
projectsFile="$configPath/projectr/projects"
else
projectsFile="$HOME/.projects"
fi
# Add to the projects file
echo -e "\033[1mAdding project to \033[34m$projectsFile\033[0;1m...\033[0m"
if ! echo "$(readlink -f "$project")" >> "$projectsFile"; then
echo -e " => \033[31mSomething went wrong.\033[0m" >&2
exit 1
fi
+4 -1
View File
@@ -66,7 +66,10 @@ revision="${2:-latest}"
# Load configuration
CONFIG_PRESERVE_VERSIONS=5
CONFIG_HASH_LENGTH=40
if [[ -f "$HOME/.project.cnf" ]]; then
configPath=${XDG_CONFIG_HOME:-$HOME/.config}
if [[ -f "$configPath/projectr/config.sh" ]]; then
source "$configPath/projectr/config.sh"
elif [[ -f "$HOME/.project.cnf" ]]; then
source "$HOME/.project.cnf"
fi
if [[ $CONFIG_PRESERVE_VERSIONS == 1 ]]; then
+12 -4
View File
@@ -8,11 +8,19 @@
# Usage: project_list
########################################################################
# Check if the ~/.project file exists
if [[ ! -f "$HOME/.projects" ]]; then
echo -e "\033[31mThere is no \033[34m~/.projects\033[31m file yet.\033[0m" >&2
# Determine the path to the projects file
configPath=${XDG_CONFIG_HOME:-$HOME/.config}
if [[ -d "$configPath/projectr" ]]; then
projectsFile="$configPath/projectr/projects"
else
projectsFile="$HOME/.projects"
fi
# Check if the projects file exists
if [[ ! -f "$projectsFile" ]]; then
echo -e "\033[31mThere is no \033[34m$projectsFile\033[31m file yet.\033[0m" >&2
exit 1
fi
cat "$HOME/.projects"
cat "$projectsFile"
exit $?
+4 -1
View File
@@ -20,7 +20,10 @@ origin="$2"
# Load configuration
CONFIG_DEFAULT_BRANCH="master"
if [[ -f "$HOME/.project.cnf" ]]; then
configPath=${XDG_CONFIG_HOME:-$HOME/.config}
if [[ -f "$configPath/projectr/config.sh" ]]; then
source "$configPath/projectr/config.sh"
elif [[ -f "$HOME/.project.cnf" ]]; then
source "$HOME/.project.cnf"
fi
+11 -3
View File
@@ -32,10 +32,18 @@ if ! rm -Rf $project; then
fi
echo -e " => \033[32mSuccess.\033[0m"
# Remove from ~/.projects
echo -e "\033[1mRemoving project from \033[34m~/.projects\033[0;1m...\033[0m"
# Determine the path to the projects file
configPath=${XDG_CONFIG_HOME:-$HOME/.config}
if [[ -d "$configPath/projectr" ]]; then
projectsFile="$configPath/projectr/projects"
else
projectsFile="$HOME/.projects"
fi
# Remove from the projects file
echo -e "\033[1mRemoving project from \033[34m$projectsFile\033[0;1m...\033[0m"
realpath="$(readlink -f "$project")"
if ! sed -i "/${realpath//\//\/}/d" "$HOME/.projects"; then # Replace / with \/ because of the sed separators
if ! sed -i "/${realpath//\//\/}/d" "$projectsFile"; then # Replace / with \/ because of the sed separators
echo -e " => \033[31mSomething went wrong.\033[0m" >&2
exit 1
fi