Last active
June 16, 2023 13:39
-
-
Save sbatial/97d01792e66221991b795e1921da35fc to your computer and use it in GitHub Desktop.
Prompt to choose from recent bartib projects.
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
#! /usr/bin/env nix-shell | |
#! nix-shell --packages bartib gum bash toybox gawk -i bash | |
# Make sure all dependencies are present | |
# toybox contains tac, head, tail | |
# Get current status of bartib | |
CURRENT_PROJ=$(bartib current) | |
# Put selection in function to ensure shorter lines | |
select_task() | |
{ | |
return |\ | |
bartib last |\ | |
tail -n+3 |\ | |
head -n-1 |\ | |
gum filter --height 10 |\ | |
awk -F' ' '{print gensub(/[^[:digit:]]/, "", "g", $1)}' | |
} | |
# Select a recent task with gum and get it's id | |
SELECTED_TASK=$(select_task) | |
# If no project is currently running: Just start the selected and finish | |
if [[ $CURRENT_PROJ = "No Activity is currently running" ]] | |
then | |
bartib continue $SELECTED_TASK | |
exit 0; | |
fi | |
# If a project is already being tracked and the user has chosen | |
# the last one regardless (which will be the currently tracked one): | |
# Ask for confirmation | |
if [[ 0 = $SELECTED_TASK ]] | |
then | |
gum confirm "Chosen project is already tracked. | |
Restart regardless?" --default=false && bartib continue $SELECTED_TASK | |
else | |
bartib continue $SELECTED_TASK | |
fi |
If nix is not installed or the following are on the system installed anyways, the shebang can be omitted:
- bartib
- gum
- tac
- head
- tail
- bash
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I use nikolassv/bartib to track my work and I found myself regularly using
bartib last
followed bybartib continue <n>
to continue one of my recently tracked projects.So I wrote this script to instead have a interactive selection build with charmbracelet/gum.