Skip to content

Instantly share code, notes, and snippets.

@karngyan
Created May 10, 2024 07:24
Show Gist options
  • Save karngyan/020582a5ae38e1d8727c5b8bd63f6410 to your computer and use it in GitHub Desktop.
Save karngyan/020582a5ae38e1d8727c5b8bd63f6410 to your computer and use it in GitHub Desktop.
Adds linear issue title to your prompt in p10k theme + omz (tested only on mac)
function prompt_linear_issue() {
if git rev-parse --git-dir > /dev/null 2>&1; then
local git_root=$(git rev-parse --show-toplevel)
local id=$(git rev-parse --abbrev-ref HEAD)
local cache_file="$git_root/.git/issue_title_cache_$id" # cache file unique to each branch
# fetch current time & file mod time
local current_time=$(date +%s)
local file_mod_time=$(date -r "$cache_file" +%s 2>/dev/null || echo 0)
# check if cache file exists and is less than an hour old
if [[ -f "$cache_file" ]] && (( current_time - file_mod_time < 3600 )); then
local issue_name=$(<"$cache_file")
else
local id=$(git rev-parse --abbrev-ref HEAD)
if [[ "$id" =~ ^[a-zA-Z]+-[0-9]+$ ]]; then
local issue_name=$(curl -s -H "Authorization: <personal_api_key>" -H "Content-Type: application/json" \
-X POST -d '{"query": "query { issue(id: \"'$id'\") { title } }"}' \
https://api.linear.app/graphql | jq -r '.data.issue.title')
# cache the issue name
echo "$issue_name" > "$cache_file"
else
return 0
fi
fi
if [[ -n "$issue_name" ]]; then
p10k segment -f 183 -i '✸' -t "$issue_name"
fi
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment