From 6e7ebb6ed79fba1ede047550773858d29fcc1be9 Mon Sep 17 00:00:00 2001 From: Locke D Date: Thu, 20 Jun 2024 01:04:06 +1000 Subject: [PATCH] updated bash config --- .bash_aliases | 21 ++++++++++++++ .local/bin/project | 71 +++++++++++++++++++++++++++++++++++++++++++++ .local/bin/projects | 23 +++++++++++++++ 3 files changed, 115 insertions(+) create mode 100644 .bash_aliases create mode 100755 .local/bin/project create mode 100755 .local/bin/projects diff --git a/.bash_aliases b/.bash_aliases new file mode 100644 index 0000000..7c70c0e --- /dev/null +++ b/.bash_aliases @@ -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' diff --git a/.local/bin/project b/.local/bin/project new file mode 100755 index 0000000..88120e7 --- /dev/null +++ b/.local/bin/project @@ -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] " + 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 diff --git a/.local/bin/projects b/.local/bin/projects new file mode 100755 index 0000000..0b4299b --- /dev/null +++ b/.local/bin/projects @@ -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