Last active
December 22, 2022 14:03
-
-
Save tyjak/6509cdf90fe43fa4017bef50ad63f909 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/zsh | |
# | |
# i3 new workspace based on folder or git name selected by fzf menu | |
# | |
# GistID: 6509cdf90fe43fa4017bef50ad63f909 | |
cd $1 | |
sleep 0.1 | |
FILE_TO_OPEN=$(fd | fzf --reverse --height=20% --no-info --color=dark,pointer:#859900,prompt:#859900,fg:#002b36,bg:#eee8d5,bg+:#859900,fg+:#002b36,marker:#eee8d5,pointer:#eee8d5,query:#002b36,hl:#859900,hl+:#eee8d5) | |
PATH_TO_FILE=$(realpath $FILE_TO_OPEN) | |
if [ -n "$FILE_TO_OPEN" ] | |
then | |
FILE_DIR=$(dirname $PATH_TO_FILE) | |
#WORKSPACE_NAME=[ "$FILE_DIR" = "." ] && "$1" || $FILE_DIR | |
if [ -d "$FILE_TO_OPEN" ] | |
then | |
cd $FILE_TO_OPEN | |
WORKSPACE_NAME=$FILE_TO_OPEN | |
FILE_DIR=$(pwd) | |
if [ -d ".git" ] | |
then | |
LOGO=" " | |
fi | |
nohup i3-msg workspace "${LOGO}$(echo -n $WORKSPACE_NAME | sed 's:/$::' | rev | cut -d"/" -f1 | rev)"; exec alacritty --working-directory="$FILE_DIR" >/dev/null & | |
elif [ $(cd $FILE_DIR && git rev-parse --show-toplevel) ] | |
then | |
cd $FILE_DIR | |
FILE_DIR=$(git rev-parse --show-toplevel) | |
WORKSPACE_NAME="$FILE_DIR" | |
LOGO=" " | |
if [ ! -d "${PATH_TO_FILE}" ] | |
then | |
# FIXME: can't concatenate this part to be executed, obliged to re-write whole line... | |
#EDIT_FILE="-e /usr/bin/vim ${PATH_TO_FILE}" | |
nohup i3-msg workspace "${LOGO}$(echo -n $WORKSPACE_NAME | rev | cut -d"/" -f1 | rev)"; exec alacritty --working-directory="$FILE_DIR" -e /usr/bin/vim ${PATH_TO_FILE} >/dev/null & | |
else | |
nohup i3-msg workspace "${LOGO}$(echo -n $WORKSPACE_NAME | rev | cut -d"/" -f1 | rev)"; exec alacritty --working-directory="$FILE_DIR" >/dev/null & | |
fi | |
#echo "i3-msg workspace \"${LOGO}$(echo -n $WORKSPACE_NAME | rev | cut -d"/" -f1 | rev)\"; exec alacritty --working-directory=\"$FILE_DIR\" $EDIT_FILE &" > ~/log.txt | |
#nohup i3-msg workspace "${LOGO}$(echo -n $WORKSPACE_NAME | rev | cut -d"/" -f1 | rev)"; exec alacritty --working-directory="$FILE_DIR" ${EDIT_FILE} & | |
fi | |
# FIXME get only on line of i3msqg for better code | |
#nohup i3-msg workspace "${LOGO}$(echo -n $WORKSPACE_NAME | rev | cut -d"/" -f1 | rev)"; exec alacritty --working-directory="$FILE_DIR" $EXE & | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment