.history/pwsh-wakatime_20210223105946.ps1
# wakatime for powershell # # include this file in your `$profile` # # Don't forget to create and configure your "~/.wakatime.cfg" file. ## PROMPT MANAGEMENT ########################################################### <# .SYNOPSIS Modifies the current prompt to send wakatime a tick. .EXAMPLE Send-HeartbeatAtPrompt Causes a WakaTime heartbeat sent at the current session's prompt. #> # We use the same procedure to nest prompts as we did for nested tab completion. if (Test-Path Function:\prompt) { Rename-Item Function:\prompt WakaTimePromptBackup } else { function WakaTimePromptBackup() { # Restore a basic prompt if the definition is missing. "PS $($executionContext.SessionState.Path.CurrentLocation)$('>' * ($nestedPromptLevel + 1)) "; } } function Send-HeartbeatAtPrompt() { function global:prompt() { if ($Env:CONDA_PROMPT_MODIFIER) { $Env:CONDA_PROMPT_MODIFIER | Write-Host -NoNewline } CondaPromptBackup; } } # hook function to send wakatime a tick pre_prompt_command() { version="1.0.0" entity=$(echo $(fc -ln -0) | cut -d ' ' -f1) [ -z "$entity" ] && return # $entity is empty or only whitespace $(git rev-parse --is-inside-work-tree 2> /dev/null) && local project="$(basename $(git rev-parse --show-toplevel))" || local project="Terminal" (wakatime --write --plugin "bash-wakatime/$version" --entity-type app --project "$project" --entity "$entity" 2>&1 > /dev/null &) } PROMPT_COMMAND="pre_prompt_command; $PROMPT_COMMAND" |