-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·55 lines (50 loc) · 1.6 KB
/
Copy pathsetup.sh
File metadata and controls
executable file
·55 lines (50 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/bin/bash
SCRIPTS_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
supported_scripts=("open" "cheatsheet" "organize")
# Colors for output
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
BLUE='\033[0;34m'
NC='\033[0m'
function shell_config_file() {
USER_SHELL=$(basename "$SHELL")
local config_file
case "$USER_SHELL" in
zsh)
config_file="${HOME}/.zshrc"
echo -e "${GREEN}Detected zsh shell${NC}" >&2
;;
bash)
config_file="${HOME}/.bashrc"
echo -e "${GREEN}Detected bash shell${NC}" >&2
;;
*)
config_file="${HOME}/.bashrc"
echo -e "${YELLOW}Unrecognized shell ${USER_SHELL}, defaulting to bash configuration${NC}" >&2
;;
esac
echo "$config_file"
}
function add_alias() {
local script="$1"
local shell_config="$2"
# Check if alias already exists
if grep -q "alias ${script}=" "${shell_config}"; then
echo -e "${YELLOW}Alias for ${script} already exists in ${shell_config}${NC}"
return
fi
echo -e "${GREEN}Adding alias for ${script} to ${shell_config}${NC}"
echo "alias ${script}='${SCRIPTS_DIR}/.venv/bin/python ${SCRIPTS_DIR}/${script}/${script}.py'" >>"${shell_config}"
}
function setup_aliases() {
local shell_config="$1"
shift
for script in "$@"; do
add_alias "$script" "$shell_config"
done
}
# Get shell config file
SHELL_CONFIG=$(shell_config_file)
echo -e "${BLUE}Setting up aliases in ${SHELL_CONFIG}${NC}"
setup_aliases "$SHELL_CONFIG" "${supported_scripts[@]}"
echo -e "${GREEN}Alias setup complete. Please run 'source ${SHELL_CONFIG}' to apply changes.${NC}"