changed how aliases are stored. Intead of the .zshrc etc. aliases now have their own file located at ~/.config/fabric/fabric-bootstrap.inc which is created during setup.sh. Please run ./setup.sh and these changes will be made automatically. your .zshrc/.bashrc will also be automatically updated
This commit is contained in:
parent
d1463e9cc7
commit
24e1616864
@ -355,13 +355,9 @@ class Alias:
|
|||||||
self.config_files = []
|
self.config_files = []
|
||||||
home_directory = os.path.expanduser("~")
|
home_directory = os.path.expanduser("~")
|
||||||
self.patterns = os.path.join(home_directory, ".config/fabric/patterns")
|
self.patterns = os.path.join(home_directory, ".config/fabric/patterns")
|
||||||
if os.path.exists(os.path.join(home_directory, ".bashrc")):
|
if os.path.exists(os.path.join(home_directory, ".config/fabric/fabric-bootstrap.inc")):
|
||||||
self.config_files.append(os.path.join(home_directory, ".bashrc"))
|
|
||||||
if os.path.exists(os.path.join(home_directory, ".zshrc")):
|
|
||||||
self.config_files.append(os.path.join(home_directory, ".zshrc"))
|
|
||||||
if os.path.exists(os.path.join(home_directory, ".bash_profile")):
|
|
||||||
self.config_files.append(os.path.join(
|
self.config_files.append(os.path.join(
|
||||||
home_directory, ".bash_profile"))
|
home_directory, ".config/fabric/fabric-bootstrap.inc"))
|
||||||
self.remove_all_patterns()
|
self.remove_all_patterns()
|
||||||
self.add_patterns()
|
self.add_patterns()
|
||||||
print('Aliases added successfully. Please restart your terminal to use them.')
|
print('Aliases added successfully. Please restart your terminal to use them.')
|
||||||
@ -584,10 +580,9 @@ class Setup:
|
|||||||
user_home = os.path.expanduser("~")
|
user_home = os.path.expanduser("~")
|
||||||
sh_config = None
|
sh_config = None
|
||||||
# Check for shell configuration files
|
# Check for shell configuration files
|
||||||
if os.path.exists(os.path.join(user_home, ".bashrc")):
|
if os.path.exists(os.path.join(user_home, ".config/fabric/fabric-bootstrap.inc")):
|
||||||
sh_config = os.path.join(user_home, ".bashrc")
|
sh_config = os.path.join(
|
||||||
elif os.path.exists(os.path.join(user_home, ".zshrc")):
|
user_home, ".config/fabric/fabric-bootstrap.inc")
|
||||||
sh_config = os.path.join(user_home, ".zshrc")
|
|
||||||
else:
|
else:
|
||||||
print("No environment file found.")
|
print("No environment file found.")
|
||||||
if sh_config:
|
if sh_config:
|
||||||
@ -628,10 +623,9 @@ class Setup:
|
|||||||
user_home = os.path.expanduser("~")
|
user_home = os.path.expanduser("~")
|
||||||
sh_config = None
|
sh_config = None
|
||||||
# Check for shell configuration files
|
# Check for shell configuration files
|
||||||
if os.path.exists(os.path.join(user_home, ".bashrc")):
|
if os.path.exists(os.path.join(user_home, ".config/fabric/fabric-bootstrap.inc")):
|
||||||
sh_config = os.path.join(user_home, ".bashrc")
|
sh_config = os.path.join(
|
||||||
elif os.path.exists(os.path.join(user_home, ".zshrc")):
|
user_home, ".config/fabric/fabric-bootstrap.inc")
|
||||||
sh_config = os.path.join(user_home, ".zshrc")
|
|
||||||
|
|
||||||
if sh_config:
|
if sh_config:
|
||||||
with open(sh_config, "r") as f:
|
with open(sh_config, "r") as f:
|
||||||
|
80
setup.sh
80
setup.sh
@ -13,59 +13,55 @@ poetry install
|
|||||||
|
|
||||||
# List of commands to check and add or update alias for
|
# List of commands to check and add or update alias for
|
||||||
# Add 'yt' and 'ts' to the list of commands
|
# Add 'yt' and 'ts' to the list of commands
|
||||||
commands=("fabric" "fabric-api" "fabric-webui" "ts", "yt")
|
commands=("fabric" "fabric-api" "fabric-webui" "ts" "yt")
|
||||||
|
|
||||||
|
# Path to the bootstrap file
|
||||||
|
bootstrap_file="$HOME/.config/fabric/fabric-bootstrap.inc"
|
||||||
|
|
||||||
|
# Ensure the directory for the bootstrap file exists
|
||||||
|
mkdir -p "$(dirname "$bootstrap_file")"
|
||||||
|
|
||||||
|
# Start the bootstrap file with a shebang if it doesn't already exist
|
||||||
|
if [ ! -f "$bootstrap_file" ]; then
|
||||||
|
echo "#!/bin/bash" > "$bootstrap_file"
|
||||||
|
fi
|
||||||
|
|
||||||
# List of shell configuration files to update
|
# List of shell configuration files to update
|
||||||
config_files=("$HOME/.bashrc" "$HOME/.zshrc" "$HOME/.bash_profile")
|
config_files=("$HOME/.bashrc" "$HOME/.zshrc" "$HOME/.bash_profile")
|
||||||
|
|
||||||
# Initialize an array to hold the paths of the sourced files
|
|
||||||
source_commands=()
|
|
||||||
|
|
||||||
for config_file in "${config_files[@]}"; do
|
for config_file in "${config_files[@]}"; do
|
||||||
# Check if the configuration file exists
|
# Check if the configuration file exists
|
||||||
if [ -f "$config_file" ]; then
|
if [ -f "$config_file" ]; then
|
||||||
echo "Updating $config_file"
|
echo "Checking $config_file"
|
||||||
for cmd in "${commands[@]}"; do
|
|
||||||
# Get the path of the command
|
# Ensure the bootstrap script is sourced from the shell configuration file
|
||||||
CMD_PATH=$(poetry run which $cmd 2>/dev/null)
|
source_line="if [ -f \"$bootstrap_file\" ]; then . \"$bootstrap_file\"; fi"
|
||||||
|
if ! grep -qF -- "$source_line" "$config_file"; then
|
||||||
|
echo -e "\n# Load custom aliases\n$source_line" >> "$config_file"
|
||||||
|
echo "Added source command for $bootstrap_file in $config_file."
|
||||||
|
fi
|
||||||
|
sed -i '/alias fabric=/d' "$config_file"
|
||||||
|
sed -i '/fabric --pattern/d' "$config_file"
|
||||||
|
|
||||||
# Check if CMD_PATH is empty
|
|
||||||
if [ -z "$CMD_PATH" ]; then
|
|
||||||
echo "Command $cmd not found in the current Poetry environment."
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Check if the config file contains an alias for the command
|
|
||||||
if grep -qE "alias $cmd=|alias $cmd =" "$config_file"; then
|
|
||||||
# Compatibility with GNU and BSD sed: Check for operating system and apply appropriate sed syntax
|
|
||||||
if [[ "$OSTYPE" == "darwin"* ]]; then
|
|
||||||
# BSD sed (macOS)
|
|
||||||
sed -i '' "/alias $cmd=/c\\
|
|
||||||
alias $cmd='$CMD_PATH'" "$config_file"
|
|
||||||
else
|
|
||||||
# GNU sed (Linux and others)
|
|
||||||
sed -i "/alias $cmd=/c\alias $cmd='$CMD_PATH'" "$config_file"
|
|
||||||
fi
|
|
||||||
echo "Updated alias for $cmd in $config_file."
|
|
||||||
else
|
|
||||||
# If not, add the alias to the config file
|
|
||||||
echo -e "\nalias $cmd='$CMD_PATH'" >>"$config_file"
|
|
||||||
echo "Added alias for $cmd to $config_file."
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
# Add to source_commands array
|
|
||||||
source_commands+=("$config_file")
|
|
||||||
else
|
else
|
||||||
echo "$config_file does not exist."
|
echo "$config_file does not exist."
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
# Provide instruction to source the updated files
|
# Add aliases to the bootstrap file
|
||||||
if [ ${#source_commands[@]} -ne 0 ]; then
|
for cmd in "${commands[@]}"; do
|
||||||
echo "To apply the changes, please run the following command(s) in your terminal:"
|
CMD_PATH=$(poetry run which $cmd 2>/dev/null)
|
||||||
for file in "${source_commands[@]}"; do
|
if [ -z "$CMD_PATH" ]; then
|
||||||
echo "source $file"
|
echo "Command $cmd not found in the current Poetry environment."
|
||||||
done
|
continue
|
||||||
else
|
fi
|
||||||
echo "No configuration files were updated. No need to source."
|
|
||||||
fi
|
# Check if the alias already exists in the bootstrap file
|
||||||
|
if ! grep -qF "alias $cmd=" "$bootstrap_file"; then
|
||||||
|
echo "alias $cmd='$CMD_PATH'" >> "$bootstrap_file"
|
||||||
|
echo "Added alias for $cmd to $bootstrap_file."
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "Setup completed. Please restart your terminal or source your configuration files to apply changes."
|
||||||
|
Loading…
x
Reference in New Issue
Block a user