├── LICENSE ├── README.md └── df.tmux /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright © 2022 tassaron 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Tmux-df 2 | 3 | Simply puts the output of `df -h` in the Tmux statusbar. Please feel free to submit pull requests with related options and features. 4 | 5 | 6 | ## Format strings (add to tmux statusbar) 7 | 8 | * `#{df_avail}`: prints `avail` column for disk mounted as `/` 9 | * `#{df_percent}`: prints `use%` column for disk mounted as `/` 10 | * `#{df_avail_private[1-5]}`: prints `avail` column for disk mounted as defined by `df_cmd_private[1-5]` 11 | * `#{df_percent_private[1-5]}`: prints `use%` column for disk mounted as defined by `df_cmd_private[1-5]` 12 | 13 | Define more mounted points such as: 14 | ``` 15 | set -g @df_cmd_private1 "$HOME/code" 16 | set -g @df_cmd_private2 "/dev" 17 | ``` 18 | 19 | 20 | ## Installation with [Tmux Plugin Manager](https://github.com/tmux-plugins/tpm) (recommended) 21 | 22 | Add plugin to the list of TPM plugins in `.tmux.conf`: 23 | 24 | set -g @plugin 'tassaron/tmux-df' 25 | 26 | Hit `prefix + I` to fetch the plugin and source it. 27 | 28 | If format strings are added to `status-right` or `status-left`, they should now be visible. 29 | 30 | 31 | ## Updating with Tmux Plugin Manager 32 | 33 | Use TPM update command: `prefix` + U 34 | 35 | 36 | ## Manual Installation 37 | 38 | Clone the repo: 39 | 40 | $ git clone https://github.com/tassaron/tmux-df ~/.tmux/plugins 41 | 42 | Add this line to the bottom of `.tmux.conf`: 43 | 44 | run-shell ~/.tmux/plugins/tmux-df/df.tmux 45 | 46 | Reload tmux environment: 47 | 48 | $ tmux source-file ~/.tmux.conf 49 | 50 | If format strings are added to `status-right` or `status-left`, they should now be visible. 51 | 52 | 53 | ## Manual Updating 54 | 55 | Go to cloned location and pull new changes with git: 56 | 57 | $ cd ~/.tmux/plugins/tmux-df && git pull 58 | 59 | Reload tmux environment: 60 | 61 | $ tmux source-file ~/.tmux.conf 62 | 63 | 64 | ## Troubleshooting 65 | 66 | - Problem with Windows? Your git may be converting line endings to Windows format. [See TPM issue #81 for instructions on how to fix this.](https://github.com/tmux-plugins/tpm/issues/81) 67 | 68 | 69 | ## License 70 | 71 | [MIT](LICENSE) 72 | -------------------------------------------------------------------------------- /df.tmux: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | get_tmux_option() { 4 | local option=$1 5 | local default_value=$2 6 | local option_value="$(tmux show-option -gqv "$option")" 7 | 8 | if [[ -z "$option_value" ]]; then 9 | echo "$default_value" 10 | else 11 | echo "$option_value" 12 | fi 13 | } 14 | 15 | DF_CMD_PRIVATE=( 16 | $(get_tmux_option "@df_cmd_private1" "/") 17 | $(get_tmux_option "@df_cmd_private2" "/") 18 | $(get_tmux_option "@df_cmd_private3" "/") 19 | $(get_tmux_option "@df_cmd_private4" "/") 20 | $(get_tmux_option "@df_cmd_private5" "/") 21 | ) 22 | 23 | df_interpolations=( 24 | "\#{df_avail}" 25 | "\#{df_percent}" 26 | "\#{df_avail_private1}" 27 | "\#{df_percent_private1}" 28 | "\#{df_avail_private2}" 29 | "\#{df_percent_private2}" 30 | "\#{df_avail_private3}" 31 | "\#{df_percent_private3}" 32 | "\#{df_avail_private4}" 33 | "\#{df_percent_private4}" 34 | "\#{df_avail_private5}" 35 | "\#{df_percent_private5}" 36 | ) 37 | df_interpolation_cmd=( 38 | "df -h / | awk '{print \$4}' | tail -n 1" 39 | "df -h / | awk '{print \$5}' | tail -n 1" 40 | "df -h ${DF_CMD_PRIVATE[0]} | awk '{print \$4}' | tail -n 1" 41 | "df -h ${DF_CMD_PRIVATE[0]} | awk '{print \$5}' | tail -n 1" 42 | "df -h ${DF_CMD_PRIVATE[1]} | awk '{print \$4}' | tail -n 1" 43 | "df -h ${DF_CMD_PRIVATE[1]} | awk '{print \$5}' | tail -n 1" 44 | "df -h ${DF_CMD_PRIVATE[2]} | awk '{print \$4}' | tail -n 1" 45 | "df -h ${DF_CMD_PRIVATE[2]} | awk '{print \$5}' | tail -n 1" 46 | "df -h ${DF_CMD_PRIVATE[3]} | awk '{print \$4}' | tail -n 1" 47 | "df -h ${DF_CMD_PRIVATE[3]} | awk '{print \$5}' | tail -n 1" 48 | "df -h ${DF_CMD_PRIVATE[4]} | awk '{print \$4}' | tail -n 1" 49 | "df -h ${DF_CMD_PRIVATE[4]} | awk '{print \$5}' | tail -n 1" 50 | ) 51 | 52 | set_tmux_option() { 53 | local option=$1 54 | local value=$2 55 | tmux set-option -gq "$option" "$value" 56 | } 57 | 58 | do_interpolation() { 59 | local result="$1" 60 | for ((i=0; i < ${#df_interpolations[@]}; i++)); do 61 | local cmd="${df_interpolation_cmd[$i]}" 62 | cmd="#(${cmd})" 63 | result="${result//${df_interpolations[$i]}/${cmd}}" 64 | done 65 | echo "$result" 66 | } 67 | 68 | update_tmux_option() { 69 | local option=$1 70 | local option_value=$(get_tmux_option "$option") 71 | local new_option_value=$(do_interpolation "$option_value") 72 | set_tmux_option "$option" "$new_option_value" 73 | } 74 | 75 | main() { 76 | update_tmux_option "status-right" 77 | update_tmux_option "status-left" 78 | local num_status_lines=$(get_tmux_option "status" "on") 79 | case $num_status_lines in 80 | # status can be 'on', 'off', or a number from 2-5 81 | ''|*[!2-5]*) num_status_lines=1 ;; 82 | *) ;; 83 | esac 84 | for ((i=0; i < "$num_status_lines"; i++)); do 85 | update_tmux_option "status-format[$i]" 86 | done 87 | } 88 | main 89 | --------------------------------------------------------------------------------