feat: use different .dtfiles config setup
This commit is contained in:
13
.config/zsh/functions/cht.zsh
Normal file
13
.config/zsh/functions/cht.zsh
Normal file
@ -0,0 +1,13 @@
|
||||
languages=`echo "golang lua cpp c typescript nodejs" | tr ' ' '\n'`
|
||||
core_utils=`echo "xargs find mv sed awk" | tr ' ' '\n'`
|
||||
|
||||
function cht(){
|
||||
selected=`printf "$languages\n$core_utils" | fzf`
|
||||
read query\?"query:"
|
||||
|
||||
if printf $languages | grep -qs $selected; then
|
||||
curl cht.sh/$selected/`echo $query | tr ' ' '+'`
|
||||
else
|
||||
curl cht.sh/$selected~$query
|
||||
fi
|
||||
}
|
65
.config/zsh/functions/co.zsh
Normal file
65
.config/zsh/functions/co.zsh
Normal file
@ -0,0 +1,65 @@
|
||||
# Helps navigating COCO directory
|
||||
function co(){
|
||||
|
||||
cd ~/COCO
|
||||
|
||||
openCode=false
|
||||
|
||||
if [ "$1" = "o" ]; then
|
||||
1=$2;
|
||||
openCode=true
|
||||
fi
|
||||
|
||||
first_dir=${1%/*};
|
||||
second_dir=${1#*/};
|
||||
|
||||
if [ -z $first_dir ]; then
|
||||
first_dir=""
|
||||
fi
|
||||
|
||||
if [ -z $second_dir ]; then
|
||||
second_dir=""
|
||||
fi
|
||||
|
||||
if [ ! -v $first_dir ]; then
|
||||
coco_dir=$(ls | grep $first_dir | head -n 1)
|
||||
|
||||
if [ -z "$coco_dir" ]; then
|
||||
|
||||
echo "No directory exists for course $first_dir. Create a new one? (y/n)"
|
||||
|
||||
read createDir
|
||||
|
||||
if [ "$createDir" = "y" ]; then
|
||||
echo "What should the name be?"
|
||||
read dirName
|
||||
dirName=$first_dir"_$dirName"
|
||||
mkdir $dirName
|
||||
cd $dirName
|
||||
echo "Created $dirName"
|
||||
fi
|
||||
|
||||
|
||||
else
|
||||
|
||||
cd $coco_dir
|
||||
amount=$(find ./* -maxdepth 0 -type d | wc -l)
|
||||
|
||||
if [ "$amount" = "1" ]; then
|
||||
dir=$(find ./* -maxdepth 0 -type d)
|
||||
cd $dir
|
||||
fi
|
||||
|
||||
fi
|
||||
|
||||
if [ $second_dir != $first_dir ]; then
|
||||
cd $second_dir
|
||||
fi
|
||||
|
||||
fi
|
||||
|
||||
if [ $openCode = true ]; then
|
||||
code-insiders .
|
||||
fi
|
||||
|
||||
}
|
31
.config/zsh/functions/conf.zsh
Normal file
31
.config/zsh/functions/conf.zsh
Normal file
@ -0,0 +1,31 @@
|
||||
function conf(){
|
||||
|
||||
OLD_PWD=$PWD;
|
||||
|
||||
if [ "$1" = "u" ]; then
|
||||
source ~/.zshrc
|
||||
elif [ "$1" = "ssh" ]; then
|
||||
cd $HOME/.ssh/
|
||||
nvim config
|
||||
else
|
||||
cd ~/.dotfiles/
|
||||
|
||||
if [ "$1" != "" ]; then
|
||||
cd configs
|
||||
cd $1
|
||||
fi
|
||||
|
||||
if [[ -f ".zshrc" ]]; then
|
||||
nvim .zshrc
|
||||
source ~/.zshrc
|
||||
elif [[ -f "config" ]]; then
|
||||
nvim config
|
||||
else
|
||||
nvim .
|
||||
fi
|
||||
|
||||
fi
|
||||
|
||||
cd $OLD_PWD
|
||||
|
||||
}
|
13
.config/zsh/functions/dv.zsh
Normal file
13
.config/zsh/functions/dv.zsh
Normal file
@ -0,0 +1,13 @@
|
||||
function dv(){
|
||||
tmux splitw -v -p20
|
||||
tmux splitw -h
|
||||
# tmux splitw -p90
|
||||
# tmux splitw -dp22 # 20/90
|
||||
# tmux splitw -h
|
||||
# tmux selectp -t'{right}'
|
||||
# tmux splitw -p80
|
||||
# tmux splitw -p56 # (15+15+15)/80
|
||||
# tmux splitw -p50
|
||||
tmux selectp -t'{top-left}'
|
||||
nvim .
|
||||
}
|
27
.config/zsh/functions/fp.zsh
Normal file
27
.config/zsh/functions/fp.zsh
Normal file
@ -0,0 +1,27 @@
|
||||
#Helps stop processes which use ports
|
||||
|
||||
function fp(){
|
||||
|
||||
if [ "$(which lsof)" = "lsof not found" ]; then
|
||||
echo "lsof not installed"
|
||||
else
|
||||
for PORT in "$@"
|
||||
do
|
||||
if [ "$PORT" != "" ]; then
|
||||
#echo "checking ($PORT)"
|
||||
PIDS="$(lsof -t -i:$PORT)"
|
||||
AMOUNT=$(wc -w<<<$PIDS);
|
||||
|
||||
if [ $AMOUNT = 0 ]; then
|
||||
echo "No processes use port $PORT";
|
||||
else
|
||||
echo "Killing $AMOUNT process(es) using port $PORT";
|
||||
echo "$PIDS" | while IFS= read -r pid ; do
|
||||
kill -9 $pid;
|
||||
done
|
||||
fi
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
}
|
31
.config/zsh/functions/fx.zsh
Normal file
31
.config/zsh/functions/fx.zsh
Normal file
@ -0,0 +1,31 @@
|
||||
# Helps navigating Sync directory
|
||||
function fx(){
|
||||
|
||||
cd $HOME/Projects/
|
||||
|
||||
if [ ! -d $2 ]; then
|
||||
echo "dir $2 does not exists"
|
||||
if read -q '?Do you want to create it (y/n)?'; then
|
||||
mkdir $2
|
||||
else
|
||||
echo -e "\nalllrighty then, byyye"
|
||||
return
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$2" != "" ]; then
|
||||
cd $2
|
||||
fi
|
||||
|
||||
if [ "$1" = "d" ]; then
|
||||
dv
|
||||
fi
|
||||
|
||||
if [ "$1" = "v" ]; then
|
||||
nvim
|
||||
fi
|
||||
|
||||
if [ "$1" = "o" ]; then
|
||||
code-insiders .
|
||||
fi
|
||||
}
|
11
.config/zsh/functions/mv-safe.zsh
Normal file
11
.config/zsh/functions/mv-safe.zsh
Normal file
@ -0,0 +1,11 @@
|
||||
function mv-safe(){
|
||||
for OLD_NAME in "$@"
|
||||
do
|
||||
NEW_NAME="$(echo $OLD_NAME | sed -e 'y/āáǎàēéěèīíǐìōóǒòūúǔùǖǘǚǜĀÁǍÀĒÉĚÈĪÍǏÌŌÓǑÒŪÚǓÙǕǗǙǛ/aaaaeeeeiiiioooouuuuüüüüAAAAEEEEIIIIOOOOUUUUÜÜÜÜ/' | sed -e 's/[^A-Za-z0-9._-]/_/g')"
|
||||
if [ $OLD_NAME != $NEW_NAME ]; then
|
||||
mv $OLD_NAME $NEW_NAME;
|
||||
else
|
||||
echo "No need to rename $OLD_NAME";
|
||||
fi
|
||||
done
|
||||
}
|
8
.config/zsh/functions/myip.zsh
Normal file
8
.config/zsh/functions/myip.zsh
Normal file
@ -0,0 +1,8 @@
|
||||
function myip(){
|
||||
RES="$(curl -s ifconfig.co/json)"
|
||||
echo $RES | jq -r ' .ip '
|
||||
if [ "$1" = "-a" ]; then
|
||||
echo "$(echo $RES | jq -r '.country') | $(echo $RES | jq -r '.city')"
|
||||
echo "$(echo $RES | jq -r '.time_zone')"
|
||||
fi
|
||||
}
|
15
.config/zsh/functions/note.zsh
Normal file
15
.config/zsh/functions/note.zsh
Normal file
@ -0,0 +1,15 @@
|
||||
function note(){
|
||||
cd ~/Notes
|
||||
|
||||
if [ "$1" != "" ]; then
|
||||
cd $1
|
||||
fi
|
||||
|
||||
if [[ -f "index.md" ]]; then
|
||||
nvim index.md
|
||||
else
|
||||
nvim .
|
||||
fi
|
||||
}
|
||||
|
||||
compctl -/ -W ~/Notes/$@ note
|
3
.config/zsh/functions/rn.zsh
Normal file
3
.config/zsh/functions/rn.zsh
Normal file
@ -0,0 +1,3 @@
|
||||
function rn(){
|
||||
find . -name "*.$1" -exec sh -c 'mv "$0" "${0%.'$1'}.'$2'"' {} \;
|
||||
}
|
7
.config/zsh/functions/run.zsh
Normal file
7
.config/zsh/functions/run.zsh
Normal file
@ -0,0 +1,7 @@
|
||||
function run(){
|
||||
if [[ -f "package.json" ]]; then
|
||||
pnpm $1
|
||||
elif [[ -f "Makefile" ]]; then
|
||||
make $1
|
||||
fi
|
||||
}
|
12
.config/zsh/functions/ssh_selector.zsh
Executable file
12
.config/zsh/functions/ssh_selector.zsh
Executable file
@ -0,0 +1,12 @@
|
||||
function s(){
|
||||
# Get a list of all available SSH clients from the ~/.ssh/config file and pass them to fzf
|
||||
selected_client=$(grep -E "^Host\s+" ~/.ssh/config | awk '{print $2}' | fzf)
|
||||
|
||||
# Check if a selection was made
|
||||
if [ -n "$selected_client" ]; then
|
||||
# Connect to the selected SSH client
|
||||
ssh "$selected_client"
|
||||
else
|
||||
echo "No SSH client selected. Exiting."
|
||||
fi
|
||||
}
|
68
.config/zsh/functions/start.zsh
Normal file
68
.config/zsh/functions/start.zsh
Normal file
@ -0,0 +1,68 @@
|
||||
# Helps with starting stuff
|
||||
function start(){
|
||||
|
||||
serviceName=$1;
|
||||
|
||||
if [ $serviceName = "docker" ]; then
|
||||
|
||||
dockerStatus="$(service docker status)"
|
||||
|
||||
if [ "${dockerStatus#*"not running"}" != "$dockerStatus" ]; then
|
||||
echo "➜ starting docker"
|
||||
echo "➜ $(sudo service docker start)"
|
||||
fi
|
||||
|
||||
sleep 0.5
|
||||
|
||||
elif [ $serviceName = "mongo" ]; then
|
||||
|
||||
start docker
|
||||
|
||||
start container mongo
|
||||
|
||||
elif [ $serviceName = "dc" ]; then
|
||||
|
||||
start docker
|
||||
|
||||
echo "➜ starting docker-compose"
|
||||
|
||||
dc up -d
|
||||
|
||||
elif [ $serviceName = "spring" ]; then
|
||||
|
||||
start mongo
|
||||
|
||||
echo "➜ starting spring-boot"
|
||||
|
||||
mvn spring-boot:run
|
||||
|
||||
elif [ $serviceName = "container" ]; then
|
||||
|
||||
containerName=$2;
|
||||
|
||||
containerInfo="[port:$(docker port $containerName) volume:$(docker inspect -f '{{index (.HostConfig.Binds) 0}}' $containerName)]"
|
||||
|
||||
containerIsRunning="$(docker inspect -f '{{.State.Running}}' $containerName 2>/dev/null)"
|
||||
|
||||
containerStatus="$(docker inspect -f '{{.State.Status}}' $containerName 2>/dev/null)"
|
||||
|
||||
if [ $containerIsRunning = "true" ]; then
|
||||
echo "➜ $containerName already running $containerInfo"
|
||||
elif [ $containerStatus = "exited" ]; then
|
||||
echo "➜ running $containerName $containerInfo"
|
||||
echo "➜ id:$(sudo docker start $containerName)"
|
||||
else
|
||||
echo "➜ container $containerName $containerInfo doesnt exist"
|
||||
fi
|
||||
|
||||
elif [ $serviceName = "dc" ]; then
|
||||
|
||||
start docker
|
||||
|
||||
echo "➜ starting docker-compose"
|
||||
|
||||
dc up -d
|
||||
|
||||
fi
|
||||
|
||||
}
|
22
.config/zsh/functions/sum.zsh
Normal file
22
.config/zsh/functions/sum.zsh
Normal file
@ -0,0 +1,22 @@
|
||||
function sum(){
|
||||
|
||||
URL=$1
|
||||
|
||||
#echo "URL: $URL";
|
||||
|
||||
TEXT=$(lynx -notitle -nonumbers -trim_input_fields -nobrowse -hiddenlinks=ignore --dump $URL | xargs | sed -e 's!http\(s\)\{0,1\}://[^[:space:]]*!!g' | sed -e 's/\[[^][]*\]//g')
|
||||
DEEP_API_KEY="a2de657c-75d0-4a7c-acdf-3b886f860282"
|
||||
|
||||
#echo "--------------------";
|
||||
#echo $TEXT
|
||||
#echo "--------------------";
|
||||
|
||||
RESULT_JSON=$(curl --silent -F "text=$TEXT" -H "api-key:$DEEP_API_KEY" https://api.deepai.org/api/summarization )
|
||||
|
||||
#echo "JSON: $RESULT_JSON"
|
||||
|
||||
RESULT=$(echo $RESULT_JSON | tr '\r\n' ' ' | jq ".output")
|
||||
|
||||
echo $RESULT
|
||||
|
||||
}
|
22
.config/zsh/functions/wp.zsh
Normal file
22
.config/zsh/functions/wp.zsh
Normal file
@ -0,0 +1,22 @@
|
||||
# Helps navigating wordpress directory
|
||||
function wp(){
|
||||
|
||||
first_dir=${1%/*}
|
||||
second_dir=${1#*/}
|
||||
|
||||
if [ $first_dir = $second_dir ]; then
|
||||
second_dir=""
|
||||
fi
|
||||
|
||||
if [ $first_dir = "plugins" ]; then
|
||||
cd "wp-content/plugins"
|
||||
elif [ $first_dir = "themes" ]; then
|
||||
cd "wp-content/themes"
|
||||
fi
|
||||
|
||||
if [ $second_dir != "" ]; then
|
||||
|
||||
fi
|
||||
|
||||
|
||||
}
|
Reference in New Issue
Block a user