Skip to content

Commit

Permalink
master : improved ergonomics and git functions
Browse files Browse the repository at this point in the history
  • Loading branch information
jbhouse committed May 26, 2024
1 parent 332e941 commit 105ae9d
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 57 deletions.
11 changes: 11 additions & 0 deletions .config/tmuxinator/diff.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: diff

windows:
- micro:
layout: tiled
# Synchronize all panes of this window, can be enabled before or after the pane commands run.
# 'before' represents legacy functionality and will be deprecated in a future release, in favour of 'after'
# synchronize: after
panes:
- gitDiffStaged
- gitDiffUnstaged
9 changes: 5 additions & 4 deletions .zsh_aliases
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,19 @@ alias ilocal="idea ~/.zsh_local/.zsh_env_local"

# git aliases
alias gs="git status"
alias gas="git add . && git stash"
alias gas="gitAddStash"
alias gaso="git stash apply 0"
alias gpo="git pull origin"
# this will unstage the last commit
alias gu="git reset --soft HEAD~1"
#alias gb="git branch --show-current"
# alias branches="git branch -r | sed \"s|origin/||\" | fzf"
# alias branch="git branch --show-current"
# alias gbc="branch | $CLIPBOARD"
# alias gcb="git checkout -b"
alias gac="git-add-commit"
alias gcob="git-branch-checkout"
alias gacp="git-add-commit-push"
alias gac="gitAddCommit"
alias gcob="gitBranchCheckout"
alias gacp="gitAddCommitPush"
alias gcom="git checkout main && git pull"
alias gpom="git pull origin main"
alias clone="git clone"
Expand Down
105 changes: 58 additions & 47 deletions .zsh_functions
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
# /\1/ : and replace with the first backslash-bracketed expression you found

function key() { rm -rf ~/.ssh/id_ed25519 && ln -s ~/.ssh/id_ed25519.$1 ~/.ssh/id_ed25519 && rm -rf ~/.ssh/id_ed25519.pub && ln -s ~/.ssh/id_ed25519.pub.$1 ~/.ssh/id_ed25519.pub ;}
# function reports() { cmd.exe /c start microsoft-edge:$PWD/app/build/reports ;}

function treEnv() { tree env | grep .env | sed 's/.*├── //' | sed 's/.*└── //' ;}

function pipelines() {
Expand All @@ -27,8 +25,8 @@ function cc() { $* | $CLIPBOARD ;}
function cpl() { fc -ln -1 | $CLIPBOARD ;}

# maven functions
function mist() { mvn -T 1C clean install $1 -Dmaven.test.skip=true -DskipTests -Dmaven.javadoc.skip=true ;}
function mim() { mvn -pl $(ls -d */ | fzf) -amd clean install ;}
function mist() { mvn -T 1C clean install "$@" -Dmaven.test.skip=true -DskipTests -Dmaven.javadoc.skip=true ;}
function mid() { mvn -pl "$@" -amd clean install ;}

# tmux functions
# function muxr() { PROJECT=~/.config/tmuxinator/paths$(pwd)/tmuxinator.yml ; if [ -f $PROJECT ]; then tmuxinator start -p $PROJECT; else smux; fi ;}
Expand Down Expand Up @@ -100,8 +98,6 @@ function docker-container-terminal () {
function docker-container-exec () {
docker exec $(docker ps -a | fzf | awk '{print $1}') $*
}

# git functions (need to handle ??)
# tmux new-session -d -s foo 'exec pfoo'
# tmux send-keys 'bundle exec thin start' 'C-m'
# tmux rename-window 'Foo'
Expand All @@ -113,36 +109,54 @@ function docker-container-exec () {
# tmux split-window -v -t 1 'exec pfoo'
# tmux -2 attach-session -t foo

function split-and-execute() {
function splitAndExecute() {
for i in $*; do;
echo "split and execute $i"
done;
}
function git-diff-unstaged() {

# git functions (need to handle ??)
function gitDiffUnstaged() {
preview="git diff $@ --color=always -- {-1}"
git diff $@ --name-only | fzf -m --ansi --preview $preview
}
function git-diff-staged() {
git diff $@ --name-only | fzf \
-m --ansi \
--bind "ctrl-o:execute:${EDITOR:-vim} {1} > /dev/tty" \
--bind "ctrl-s:execute:git add {1} > /dev/null" \
--bind "ctrl-r:reload:git diff --name-only" \
--bind "ctrl-e:execute:git checkout {1} > /dev/null" \
--preview $preview \
--prompt "untracked changes >" \
--header $'CTRL-O (open in editor) | CTRL-S (stage) | CTRL-R (reload) | CTRL-D (revert changes)\n'
}
function gitDiffStaged() {
preview="git diff --cached $@ --color=always -- {-1}"
git diff --cached $@ --name-only | fzf -m --ansi --preview $preview
git diff --cached $@ --name-only | fzf \
-m --ansi \
--bind "ctrl-o:execute:${EDITOR:-vim} {1} > /dev/tty" \
--bind "ctrl-s:execute:git restore --staged {1} > /dev/null" \
--bind "ctrl-r:reload:git diff --cached $@ --name-only" \
--preview $preview \
--prompt "staged changes >" \
--header $'CTRL-O (open in editor) | CTRL-S (unstage) | CTRL-R (reload)\n'
}
function rclone() { (cd ~/repos && git clone "$1") ;}
function git-file-revert() {
function tclone() { (cd ~/tmp && git clone "$1") ;}
function gitFileRevert() {
FILE=$(git status --porcelain | sed 's/M //g;s/A //g;s/R //g;s/C //g;s/D //g' | fzf -m | sed 's/^[[:space:]]*//g')
if [ ! -z "$FILE" ]
then for i in $(printf %b "$FILE"); do git restore "$i"; done
then for i in $(printf %b "$FILE"); do git checkout "$i"; done
else echo 'no files selected, no changes made'
fi
}
function git-file-unstage() {
function gitFileUnstage() {
FILE=$(git status --porcelain | sed 's/M //g;s/A //g;s/R //g;s/C //g;s/D //g' | fzf -m | sed 's/^[[:space:]]*//g')
if [ ! -z "$FILE" ]
then for i in $(printf %b $FILE); do git restore --staged $i; done
else echo 'no files selected, no changes made'
fi
}
function git-stash-apply() { git stash apply $(git stash list | grep "$1" | fzf | sed -n '/:/s/stash@{//p' | sed 's/[}].*$//') ;}
function git-stash-delete-stash() {
function gitStashApply() { git stash apply $(git stash list | grep "$1" | fzf | sed -n '/:/s/stash@{//p' | sed 's/[}].*$//') ;}
function gitStashDeleteStash() {
STASHES=$(git stash list | grep "$1" | fzf -m | sed -n '/:/s/stash@{//p' | sed 's/[}].*$//')
echo "$STASHES"
if [ ! -z "$STASHES" ];
Expand All @@ -151,47 +165,44 @@ function git-stash-delete-stash() {
fi
}
#function gsa() { git stash list | grep "$1" ; echo git stash apply ; read stashNum ; git stash apply $stashNum ;}
function git-add-commit() { git add -i ; BRANCH=$(git-branch) ; git commit . -m "${BRANCH} : $*" ;}
function git-add-commit-push() {
BRANCH=$(git-branch);
function gitAdd() { gitDiffUnstaged ;}
function gitAddStash() { gitAdd ; git stash save -S $* ;}
function gitAddCommit() { gitAdd ; git commit -m "$(gitBranch) : $*" ;}
function gitAddCommitPush() {
BRANCH=$(gitBranch);
if [[ "${BRANCH}" == *"master"* ]] || [[ "${BRANCH}" == *"main"* ]] || [[ "${BRANCH}" == *"release"* ]] || [[ "${BRANCH}" == *"develop"* ]];
then echo "are you sure you want to push to ${BRANCH}? y/n" ; read answer ;
if [[ "${answer}" == "Y" ]] || [[ "${answer}" == "y" ]];
then git add . ; git commit -m "${BRANCH} : $*" ; git push ;
else echo "commit/push aborted.";
fi
else $(gac) ; git push --set-upstream origin ${BRANCH} ;
if [[ "${answer}" == "Y" ]] || [[ "${answer}" == "y" ]];
then gitAddCommit $* ; git push ;
else echo "commit/push aborted.";
fi
else gitAddCommit $* ; git push --set-upstream origin ${BRANCH} ;
fi
}
function git-branch-checkout () {
function gitBranchCheckout () {
git fetch --prune
git pull
if [[ `git status --porcelain` ]];
then
git add . ; echo 'commit or stash? c/s \n(default is to commit and check out a new branch)' ; read choice
if [ "$choice" = "stash" ] || [ "$choice" = "s" ];
then echo commit message: ; read message ; git stash save "$message"
else echo commit message: ; read message ; git commit . -m "$(git-branch) : $message"
fi
git pull
else
if [ -z "$1" ]
then git checkout $(git branch --all | fzf)
else git checkout $1
fi
git pull
fi
git pull
if [[ `git status --porcelain` ]];
then
echo 'commit or stash? c/s \n(default is to commit and check out a new branch)' ; read choice
if [ "$choice" = "stash" ] || [ "$choice" = "s" ];
then echo "stash message: " ; read message ; gitAddStash $message
else echo "commit message: " ; read message ; gitAddCommit $message
fi
gitBranchCheckout
else
if [ -z "$1" ]
then git checkout $(git branch -r | sed "s|origin/||" | fzf)
else git checkout $1
fi
git pull
fi
}

function git-branch-delete() { git branch -D $*; }
function git-branch() { git branch --show-current; }
function git-branch-copy() { git branch --show-current | $CLIPBOARD; }
function git-branch-create() { git checkout -b $*; }
function gitBranchDelete() { git branch -D $*; }
function gitBranch() { git branch --show-current; }
function gitBranchCopy() { git branch --show-current | $CLIPBOARD; }
function gitBranchCreate() { git checkout -b $*; }

# editor functions
function ij() { (cd ~/repos && idea "$(pwd)$(ls | fzf)") ; }
Expand All @@ -216,7 +227,7 @@ function j8() { updateEnvFile 8 ;}
function j11() { updateEnvFile 11 ;}
function j17() { updateEnvFile 17 ;}
function j21() { updateEnvFile 21 ;}
function backup() { (cd ~/Documents/cli && git add . && git-add-commit-push $*) ;}
function backup() { (cd ~/Documents/cli && gitAddCommitPush $*) ;}

# searching functions
function fs() { FILENAME=$(preview); if [ ! -z "$FILENAME" ] ; then micro $FILENAME ; fi ;}
Expand Down
14 changes: 14 additions & 0 deletions .zshrc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ source ~/.zsh_aliases
source ~/.zsh_functions
source ~/.oh-my-zsh/custom/zsh-syntax-highlighting/themes/catppuccin_frappe-zsh-syntax-highlighting.zsh
# source ~/.oh-my-zsh/custom/scripts/fzf-git.sh

# source ~/.oh-my-zsh/custom/plugins/fzf-tab-completion/zsh/fzf-zsh-completion.sh
# bindkey '^I' fzf_completion
# these two were needed on intel mbp

# source "/usr/local/opt/fzf/shell/completion.zsh"
# source "/usr/local/opt/fzf/shell/key-bindings.zsh"
if [[ ! -z ~/.zsh_local ]]; then ; for i in ~/.zsh_local/.*; do source $i; done ; fi
# [ -f ~/.fzf.zsh ] && source ~/.fzf.zsh

Expand All @@ -50,6 +57,9 @@ zstyle ':fzf-tab:complete:*:*' fzf-preview 'less ${(Q)realpath}'
# switch group using `,` and `.`
zstyle ':fzf-tab:*' switch-group ',' '.'

# zstyle ':completion:*' fzf-search-display true
# needed on intel?^

# User configuration
# export MANPATH="/usr/local/man:$MANPATH"

Expand All @@ -71,6 +81,10 @@ HISTSIZE=1000
SAVEHIST=1000
setopt appendhistory

# ### MANAGED BY RANCHER DESKTOP START (DO NOT EDIT)
# export PATH="/Users/P3193379/.rd/bin:$PATH"
# ### MANAGED BY RANCHER DESKTOP END (DO NOT EDIT)

# Print tree structure in the preview window
export FZF_ALT_C_OPTS="--preview 'tree -C {}'"

Expand Down
2 changes: 1 addition & 1 deletion mac/.zprofile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ eval "$(/opt/homebrew/bin/brew shellenv)"
source $(brew --prefix)/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
# source $(brew --prefix)/Cellar/fzf/**/shellcompletion.zsh
# source $(brew --prefix)/Cellar/fzf/**/shell/key-bindings.zsh
eval "$(fzf --zsh)"
#M1 ^
# eval "$(/usr/local/Homebrew/bin/brew shellenv)"
#intel ^
eval "$(fzf --zsh)"
9 changes: 4 additions & 5 deletions util_functions/.kafka_functions
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

function kafka-publish-message() {
function publishKafkaMessage() {
source ~/.zsh_env;
TOPIC_NAME=$(jq < ~/Documents/kafka_messages/kafka_map.json | fzf | awk '{ print $2 }' | sed 's/\"//' | sed 's/",.*$//');
while getopts 'e' flag; do
Expand All @@ -13,17 +13,16 @@ function kafka-publish-message() {
# echo "publishing message to $TOPIC_NAME"
jq -rc . "$HOME/Documents/kafka_messages/$TOPIC_NAME.json" | kafka-console-producer --broker-list "$BOOTSTRAP_SERVER" --topic "$TOPIC_NAME"
}

function kafka-consume-message() {
# need to first check for the existence of path: ~/Documents/kafka_messages/kafka_map.json
# need to first check for the existence of path: ~/Documents/kafka_messages/kafka_map.json
function consumeKafkaMessage() {
TOPIC_NAME=$(jq < ~/Documents/kafka_messages/kafka_map.json | fzf | awk '{ print $2 }' | sed 's/\"//' | sed 's/",.*$//');
echo "consuming from $TOPIC_NAME"
source ~/.zsh_env;
# echo "kafka-console-consumer --topic $TOPIC_NAME --bootstrap-server $BOOTSTRAP_SERVER $@"
kafka-console-consumer --topic "$TOPIC_NAME" --bootstrap-server "$BOOTSTRAP_SERVER" "$@"
}

function kafka-consume-message-formatted() {
function consumeKafkaMessageFormatted() {
TOPIC_NAME=$(jq < ~/Documents/kafka_messages/kafka_map.json | fzf | awk '{ print $2 }' | sed 's/\"//' | sed 's/",.*$//');
echo "consuming from $TOPIC_NAME"
source ~/.zsh_env;
Expand Down

0 comments on commit 105ae9d

Please sign in to comment.