updated bash config

This commit is contained in:
2024-06-20 01:04:06 +10:00
parent f8fb06e74e
commit 6e7ebb6ed7
3 changed files with 115 additions and 0 deletions

21
.bash_aliases Normal file
View File

@@ -0,0 +1,21 @@
# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
alias ls='ls --color=auto'
#alias dir='dir --color=auto'
#alias vdir='vdir --color=auto'
alias grep='grep --color=auto'
#alias fgrep='fgrep --color=auto'
#alias egrep='egrep --color=auto'
fi
# some more ls aliases
#alias ll='ls -l'
alias la='ls -A'
#alias l='ls -CF'
alias vim=nvim
alias vi=nvim
alias dotfiles='/usr/bin/git --git-dir=/home/locke/.dotfiles --work-tree=/home/locke'

71
.local/bin/project Executable file
View File

@@ -0,0 +1,71 @@
#!/usr/bin/env bash
# Default projects directory
PROJECTS_DIR="$HOME/projects"
# Function to print usage
print_usage() {
echo "Usage: $0 [-n] <project_name>"
echo "Options:"
echo " -n Create a new project directory if it does not exist"
}
# Check if at least one argument is provided
if [ $# -eq 0 ]; then
print_usage
exit 1
fi
# Initialize variables
CREATE_NEW=false
PROJECT_NAME=""
# Parse options
while getopts ":n" opt; do
case $opt in
n)
CREATE_NEW=true
;;
\?)
echo "Invalid option: -$OPTARG"
print_usage
exit 1
;;
esac
done
# Shift the options so $1 now refers to the project name argument
shift $((OPTIND - 1))
# The argument after options is the project name
PROJECT_NAME="$1"
create_session() {
tmux has-session -t $PROJECT_NAME &> /dev/null
if [ $? != 0 ]; then
cd "$PROJECTS_DIR/$PROJECT_NAME"
tmux new -session -s $PROJECT_NAME -n nvim -d
tmux new-window -t $PROJECT_NAME: -n terminal
if [ -d "venv" ]; then
tmux send-keys -t "$PROJECT_NAME:nvim" "source venv/bin/activate" C-m
tmux send-keys -t "$PROJECT_NAME:terminal" "source venv/bin/activate" C-m
fi
tmux send-keys -t "$PROJECT_NAME:nvim" "nvim ." C-m
tmux attach -t "$PROJECT_NAME:nvim"
else
tmux attach -t $PROJECT_NAME
fi
}
# Check if the project directory exists
if [ -d "$PROJECTS_DIR/$PROJECT_NAME" ]; then
create_session
else
if [ "$CREATE_NEW" = true ]; then
mkdir -p "$PROJECTS_DIR/$PROJECT_NAME"
create_session
else
echo "Error: Project directory '$PROJECT_NAME' does not exist in $PROJECTS_DIR."
exit 1
fi
fi

23
.local/bin/projects Executable file
View File

@@ -0,0 +1,23 @@
#!/usr/bin/env bash
# Default projects directory
PROJECTS_DIR="$HOME/projects"
PROJECT_NAME=`ls $PROJECTS_DIR | fzf`
if [ -z "$PROJECT_NAME" ]; then
echo "No project selected. Exiting."
exit 1
fi
tmux has-session -t $PROJECT_NAME &> /dev/null
if [ $? != 0 ]; then
cd "$PROJECTS_DIR/$PROJECT_NAME"
tmux new -session -s $PROJECT_NAME -n nvim -d
tmux new-window -t $PROJECT_NAME: -n terminal
if [ -d "venv" ]; then
tmux send-keys -t "$PROJECT_NAME:nvim" "source venv/bin/activate" C-m
tmux send-keys -t "$PROJECT_NAME:terminal" "source venv/bin/activate" C-m
fi
tmux send-keys -t "$PROJECT_NAME:nvim" "nvim ." C-m
tmux attach -t "$PROJECT_NAME:nvim"
else
tmux attach -t $PROJECT_NAME
fi