Skip to content

Commit

Permalink
feat: git checkout interactive with fuzzy search
Browse files Browse the repository at this point in the history
  • Loading branch information
miszo committed Oct 5, 2023
1 parent 8397bc4 commit 4327631
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 14 deletions.
28 changes: 14 additions & 14 deletions home/.chezmoiscripts/darwin/run_after_install-packages.sh.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

set -eufo pipefail

{{ $packagesTimestampPath := joinPath .chezmoi.homeDir "chezmoi_install_packages_timestamp.txt" -}}
{{ $brewfilePath := joinPath .chezmoi.homeDir "Brewfile" -}}
{{ $brewBundleTimestampPath := joinPath .chezmoi.homeDir ".config" "brew" "brew_bundle_timestamp.txt" -}}
{{ $brewfilePath := joinPath .chezmoi.homeDir ".config" "brew" "Brewfile" -}}
{{ $toolVersionsPath := joinPath .chezmoi.homeDir ".tool-versions" -}}
{{ $fallbackDate := "1970-01-01T00:00:00+0000" -}}
{{ $dateFormat := "%Y-%m-%dT%H:%M:%S%z" -}}
Expand Down Expand Up @@ -31,33 +31,33 @@ function get_fallback_date_utc() {
echo {{ $fallbackDate | quote }}
}

function set_install_fallback_timestamp() {
echo "Setting current timestamp in {{ $packagesTimestampPath }}"
get_fallback_date_utc > {{ $packagesTimestampPath | quote }}
function set_bundle_fallback_timestamp() {
echo "Setting current timestamp in {{ $brewBundleTimestampPath }}"
get_fallback_date_utc > {{ $brewBundleTimestampPath | quote }}
}

function set_install_timestamp() {
echo "Setting current timestamp in {{ $packagesTimestampPath }}"
get_current_date_utc > {{ $packagesTimestampPath | quote }}
function set_bundle_timestamp() {
echo "Setting current timestamp in {{ $brewBundleTimestampPath }}"
get_current_date_utc > {{ $brewBundleTimestampPath | quote }}
}

function get_install_timestamp() {
if ! [ -e {{ $packagesTimestampPath | quote }} ]; then
set_install_fallback_timestamp
function get_bundle_timestamp() {
if ! [ -e {{ $brewBundleTimestampPath | quote }} ]; then
set_bundle_fallback_timestamp
fi
cat {{ $packagesTimestampPath | quote }}
date -r {{ $brewBundleTimestampPath }} +{{ $dateFormat | quote }}
}

function get_brewfile_timestamp() {
date -r {{ $brewfilePath }} +{{ $dateFormat | quote }}
}

function main() {
if [[ $(get_brewfile_timestamp) > $(get_install_timestamp) ]];
if [[ $(get_brewfile_timestamp) > $(get_bundle_timestamp) ]];
then
brew_bundle
asdf_install
set_install_timestamp;
set_bundle_timestamp;
fi
}

Expand Down
1 change: 1 addition & 0 deletions home/Brewfile.tmpl → home/dot_config/brew/Brewfile.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ brew 'bat'
brew 'bison'
brew 'cloc'
brew 'exa'
brew 'fzf'
brew 'gh'
brew 'git'
brew 'gitleaks'
Expand Down
2 changes: 2 additions & 0 deletions home/dot_config/git/config.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
a = add .
nb = checkout -b
co = checkout
coi = !git checkout $(git branch | fzf | xargs)
coia = !git checkout $(git branch -a | fzf | xargs)
com = checkout master
ci = commit
cim = commit -m
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,29 @@
{{- $brewBundleTimestampPath := joinPath .chezmoi.homeDir ".config" "brew" "brew_bundle_timestamp.txt" -}}
{{- $brewfilePath := joinPath .chezmoi.homeDir ".config" "brew" "Brewfile" -}}
{{ $fallbackDate := "1970-01-01T00:00:00+0000" -}}
{{ $dateFormat := "%Y-%m-%dT%H:%M:%S%z" -}}

function get_current_date_utc() {
date -u +{{ $dateFormat | quote }}
}

function set_bundle_timestamp() {
echo "Setting current timestamp in {{ $brewBundleTimestampPath }}"
get_current_date_utc > {{ $brewBundleTimestampPath | quote }}
}

function brew_bundle() {
echo "Run brew bundle..."
brew bundle --no-lock --file={{ $brewfilePath }}
set_bundle_timestamp;
}

function brew_update {
brew upgrade &&
brew update &&
brew cleanup &&
asdf reshim

}

function miszo_git_local_config {
Expand Down

0 comments on commit 4327631

Please sign in to comment.