├── bash-wakatime.sh ├── README.md └── install_cli.sh /bash-wakatime.sh: -------------------------------------------------------------------------------- 1 | # wakatime for bash 2 | # 3 | # include this file in your "~/.bashrc" file with this command: 4 | # . path/to/bash-wakatime.sh 5 | # 6 | # or this command: 7 | # source path/to/bash-wakatime.sh 8 | # 9 | # Don't forget to create and configure your "~/.wakatime.cfg" file. 10 | 11 | # hook function to send wakatime a tick 12 | pre_prompt_command() { 13 | version="1.0.0" 14 | entity=$(echo $(fc -ln -0) | cut -d ' ' -f1) 15 | [ -z "$entity" ] && return # $entity is empty or only whitespace 16 | $(git rev-parse --is-inside-work-tree 2> /dev/null) && local project="$(basename $(git rev-parse --show-toplevel))" || local project="Terminal" 17 | (~/.wakatime/wakatime-cli --write --plugin "bash-wakatime/$version" --entity-type app --project "$project" --entity "$entity" 2>&1 > /dev/null &) 18 | } 19 | 20 | PROMPT_COMMAND="pre_prompt_command; $PROMPT_COMMAND" 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | BASH plugin for wakatime 2 | ======================= 3 | 4 | Automatic time tracking for commands in BASH using [wakatime](http://wakatime.com/). 5 | 6 | Installation 7 | ------------ 8 | 9 | Make sure you have configured wakatime API key in your [~/.wakatime.cfg](https://github.com/wakatime/wakatime-cli/blob/develop/USAGE.md#ini-config-file) file. 10 | 11 | 1. Run `./install_cli.sh` to install the [WakaTime CLI](https://github.com/wakatime/wakatime-cli). 12 | 13 | 2. For bash users: 14 | - git clone https://github.com/irondoge/bash-wakatime.git 15 | 16 | - include the "bash-wakatime.sh" file in your "~/.bashrc" file with this command: 17 | 18 | `. path/to/bash-wakatime.sh` 19 | 20 | - or this command: 21 | 22 | `source path/to/bash-wakatime.sh` 23 | 24 | - But if you already have a PROMPT_COMMAND variable set, 25 | just merge your own pre_prompt_command with the following one. 26 | And don't forget to create and configure your "~/.wakatime.cfg" file. 27 | 28 | 3. Open a new terminal and type commands 29 | 30 | 4. Visit https://wakatime.com/project/Terminal 31 | -------------------------------------------------------------------------------- /install_cli.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | set -x 5 | 6 | arch="amd64" 7 | if [[ $(uname -m) == "aarch64" ]]; then 8 | arch="arm64" 9 | fi 10 | 11 | extract_to="$HOME/.wakatime" 12 | 13 | os="unknown" 14 | if [[ "$OSTYPE" == "linux-gnu"* ]]; then 15 | os="linux" 16 | elif [[ "$OSTYPE" == "darwin"* ]]; then 17 | os="darwin" 18 | elif [[ "$OSTYPE" == "cygwin" ]]; then 19 | os="windows" 20 | elif [[ "$OSTYPE" == "msys" ]]; then 21 | os="windows" 22 | elif [[ "$OSTYPE" == "win32" ]]; then 23 | os="windows" 24 | elif [[ "$OSTYPE" == "freebsd"* ]]; then 25 | os="freebsd" 26 | elif [[ "$OSTYPE" == "openbsd"* ]]; then 27 | os="openbsd" 28 | elif [[ "$OSTYPE" == "netbsd"* ]]; then 29 | os="netbsd" 30 | fi 31 | 32 | zip_file="$extract_to/wakatime-cli-${os}-${arch}.zip" 33 | symlink="$extract_to/wakatime-cli" 34 | extracted_binary="$extract_to/wakatime-cli-${os}-${arch}" 35 | if [[ "$os" == "windows" ]]; then 36 | extracted_binary="$extracted_binary.exe" 37 | fi 38 | url="https://github.com/wakatime/wakatime-cli/releases/latest/download/wakatime-cli-${os}-${arch}.zip" 39 | 40 | # make dir if not exists 41 | mkdir -p "$extract_to" 42 | 43 | cd "$extract_to" 44 | 45 | echo "Downloading wakatime-cli to $zip_file ..." 46 | curl -L "$url" -o "$zip_file" 47 | 48 | echo "Unzipping zip_file ..." 49 | unzip -q -o "$zip_file" || true 50 | 51 | ln -fs "$extracted_binary" "$symlink" 52 | chmod a+x "$extracted_binary" 53 | 54 | echo "Installed $symlink" 55 | 56 | rm "$zip_file" 57 | 58 | echo "Finished installing wakatime-cli." 59 | 60 | exit 0 61 | --------------------------------------------------------------------------------