diff options
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/gitlost | 17 | ||||
-rwxr-xr-x | scripts/note | 67 | ||||
-rwxr-xr-x | scripts/tmux-sessionizer | 25 |
3 files changed, 109 insertions, 0 deletions
diff --git a/scripts/gitlost b/scripts/gitlost new file mode 100755 index 0000000..43d5120 --- /dev/null +++ b/scripts/gitlost @@ -0,0 +1,17 @@ +#!/bin/bash + +directories=$(find ~/code/work ~/code/personal -mindepth 1 -maxdepth 1 -type d) + +for dir in $directories +do + cd "$dir" + is_git=$(git -C $dir rev-parse 2>/dev/null) + exit_code=$(echo $?) + [[ $exit_code != 0 ]] && continue + + git_status=$(git -C $dir status --porcelain 2>/dev/null) + + [[ -z $git_status ]] && continue + + echo "$dir" +done diff --git a/scripts/note b/scripts/note new file mode 100755 index 0000000..1e0188d --- /dev/null +++ b/scripts/note @@ -0,0 +1,67 @@ +#!/bin/bash + +# Owner: claw0ry <claw0ry@proton.me> +# Description: Take notes using vim. Theres a lot of assumptions here, so it might not fit your setup. +# Assumptions: +# - Your notes directory is in your $HOME +# - Your home directory is '/home/<user>/' +# - Your notes should be in markdown + +_list_files() { + find "$1" -mindepth 1 -type f | while read file; do + echo "$file" | cut -d'/' -f5- + done +} + +_remove_file() { + if [[ -f "$1" ]]; then + rm -v "$1" + else + echo "ERR: file not found" + return 1 + fi +} + +_open_file() { + # inject template if files does not already exist + if [[ ! -f "$1" ]]; then + local now=$(date -R) + local templ="# TITLE\n\nDate: $now\n\n" + + # opens a new vim buffer with $templ and sets the filename to $1 without writing to it + echo -e $templ | $EDITOR - -c ':set ft=markdown' +"file ${1}" + else + $EDITOR "$1" + fi +} + +_print_usage() { + echo "usage: note [COMMAND] [<filename>]" + echo "Commands:" + echo " list" + echo " List all notes" + echo " rm" + echo " Delete all notes" + echo " help" + echo " Prints usage" +} + +note() { + if [[ -z "$1" ]]; then + _print_usage + return 1 + fi + + case "$1" in + "list") + _list_files "$HOME/notes";; + "rm") + _remove_file "$HOME/notes/$2";; + "help") + _print_usage;; + *) + _open_file "$HOME/notes/$1";; + esac +} + +note "$@" diff --git a/scripts/tmux-sessionizer b/scripts/tmux-sessionizer new file mode 100755 index 0000000..a9a3165 --- /dev/null +++ b/scripts/tmux-sessionizer @@ -0,0 +1,25 @@ +#!/usr/bin/env bash + +if [[ $# -eq 1 ]]; then + selected=$1 +else + selected=$(find ~/code/personal ~/code/work -mindepth 1 -maxdepth 1 -type d | fzf) +fi + +if [[ -z $selected ]]; then + exit 0 +fi + +selected_name=$(basename "$selected" | tr . _) +tmux_running=$(pgrep tmux) + +if [[ -z $TMUX ]] && [[ -z $tmux_running ]]; then + tmux new-session -s $selected_name -c $selected + exit 0 +fi + +if ! tmux has-session -t=$selected_name 2> /dev/null; then + tmux new-session -ds $selected_name -c $selected +fi + +tmux switch-client -t $selected_name |