# Check if jq is installed
if ! command -v jq &> /dev/null
then
echo "jq could not be found. Please install it to use JSON features in bashrc."
# Installation instructions for user reference
# On Ubuntu/Debian: sudo apt-get install jq
# On macOS: brew install jq
else
# Define the location of your configuration file
BASH_CONFIG_FILE="$HOME/.[Link]"
# Function to get a value from the JSON config using a jq path (e.g., .api_key)
get_config_value() {
if [ -f "$BASH_CONFIG_FILE" ]; then
# The -r option outputs the raw value without quotes
jq -r "$1" "$BASH_CONFIG_FILE"
else
echo "Error: Configuration file not found at $BASH_CONFIG_FILE" >&2
fi
}
# Example Usage:
# Exporting a variable on shell startup
export MY_API_KEY=$(get_config_value '.api_key')
# Defining a custom navigation function using the aliases from the JSON file
j_nav() {
local target_path
target_path=$(get_config_value ".aliases.$1")
if [ -n "$target_path" ] && [ "$target_path" != "null" ]; then
cd "$target_path" || echo "Error: Could not change directory to $target_path"
else
echo "Alias '$1' not found in JSON config."
fi
}
fi