Improve project script so it can open a terminal and use an arbitrary project chooser. Add rofi-project

main
Ian Mancini 4 years ago
parent 6e9b025708
commit d7eab21a7f

@ -18,6 +18,10 @@ Options:
EOF EOF
} }
list_projects() {
cat $PROJECTS_FILE
}
add_project() { add_project() {
echo "Info: adding project $NEW_PROJECT_DIR" echo "Info: adding project $NEW_PROJECT_DIR"
# Check if project is already present # Check if project is already present
@ -45,7 +49,7 @@ add_project() {
} }
remove_project() { remove_project() {
PROJECT=$(cat $PROJECTS_FILE | fzf) PROJECT=$(cat $PROJECTS_FILE | eval "$FINDER")
if [ -z "$PROJECT" ]; then if [ -z "$PROJECT" ]; then
exit 0 exit 0
fi fi
@ -68,22 +72,26 @@ remove_project() {
} }
open_project() { open_project() {
PROJECT=$(cat $PROJECTS_FILE | fzf) PROJECT=$(cat $PROJECTS_FILE | eval "$FINDER")
if [ -z "$PROJECT" ]; then if [ -z "$PROJECT" ]; then
exit 0 exit 0
fi fi
if [ -d "$PROJECT" ]; then if [ -d "$PROJECT" ]; then
tmux -L $(basename "$PROJECT") attach PROJECT_BASENAME=$(basename $PROJECT)
TMUX_ARGS=""
tmux -L $PROJECT_BASENAME has-session
if [ $? == 0 ]; then if [ $? == 0 ]; then
exit 0 TMUX_ARGS="-L $PROJECT_BASENAME attach"
else
TMUX_ARGS="-L $PROJECT_BASENAME new-session -c $PROJECT"
fi
if [ $TERM == "linux" ]; then
$TERMINAL -e tmux $TMUX_ARGS
else else
OLDIR=$(pwd) tmux $TMUX_ARGS
cd "$PROJECT"
tmux -L $(basename "$PROJECT")
cd "$OLDIR"
exit 0
fi fi
else else
read -p "Error: directory for $(basename $PROJECT) not found. Remove project? [Ny]: " REMOVE_MISSING read -p "Error: directory for $(basename $PROJECT) not found. Remove project? [Ny]: " REMOVE_MISSING
@ -101,10 +109,12 @@ open_project() {
PROJECTS_FILE="$HOME/.projects" PROJECTS_FILE="$HOME/.projects"
OPEN="true" OPEN="true"
NEW_PROJECT_DIR="" NEW_PROJECT_DIR=""
FINDER="fzf"
# Parse args # Parse args
while getopts "hra" opt; do while getopts "f:hral" opt; do
case $opt in case $opt in
f) FINDER=$OPTARG ;;
a) a)
OPEN="false" OPEN="false"
if [ ! -z $OPTARG ]; then if [ ! -z $OPTARG ]; then
@ -114,12 +124,20 @@ while getopts "hra" opt; do
fi fi
add_project add_project
;; ;;
r) OPEN="false"; remove ;; r) OPEN="false"; remove_project ;;
l) list_projects; exit 0 ;;
h) OPEN="false"; help; exit 0 ;; h) OPEN="false"; help; exit 0 ;;
\?) echo "" >&2; help; exit 1 ;; \?) echo "" >&2; help; exit 1 ;;
esac esac
done done
COMMAND=$(cut -f 1 -d " " <<< $FINDER)
if ! command -v $COMMAND &> /dev/null
then
echo "$COMMAND could not be found"
exit 1
fi
if [ ! -f "$PROJECTS_FILE" ]; then if [ ! -f "$PROJECTS_FILE" ]; then
touch "$PROJECTS_FILE" touch "$PROJECTS_FILE"
echo "Info: Created projects file" echo "Info: Created projects file"

@ -0,0 +1,3 @@
#!/usr/bin/dash
exec ~/.bin/project -f "rofi -dmenu -i -p \"project\""
Loading…
Cancel
Save