Populate repo
3
tmux/.tmux/plugins/tmux-battery/.gitattributes
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
# Force text files to have unix eols, so Windows/Cygwin does not break them
|
||||
*.* eol=lf
|
||||
*.png -text
|
44
tmux/.tmux/plugins/tmux-battery/CHANGELOG.md
Normal file
@ -0,0 +1,44 @@
|
||||
# Changelog
|
||||
|
||||
### master
|
||||
- Fixed `#{battery_graph}` to actually display graph (@rux616)
|
||||
- High-granularity icons and colors added. (@rux616)
|
||||
- Changed preferred order of utility applications to be `pmset` -> `acpi` -> `upower` -> `termux-battery-status` due to CPU usage issues with `upower` (2019-03-05) (@rux616)
|
||||
- Added `#{battery_status_bg}` feature (@RyanFrantz)
|
||||
- Added multibattery output support for `upower` (@futuro)
|
||||
- Added Chromebook support (@forkjoseph)
|
||||
- Added battery graph, simplify interpolation (@levens)
|
||||
|
||||
### v1.2.0, 2016-09-24
|
||||
- show output for `#{battery_remain}` interpolation only if the battery is
|
||||
discharging
|
||||
- prevent displaying "(No" for `#{battery_remain}` interpolation (when battery
|
||||
status is "No estimate"
|
||||
- display all batteries that upower knows about (@JanAhrens)
|
||||
- acpi battery status (@cpb)
|
||||
- fix issue with status-right and status-left whitespace being cut out
|
||||
- fix issue with the `pmset -g batt` command output for macOS Sierra and further
|
||||
|
||||
### v1.1.0, 2015-03-14
|
||||
- change the default icon for "attached" battery state from :snail: to :warning:
|
||||
- add support for OS X "attached" battery state (@m1foley)
|
||||
- add `#{battery_remain}` feature (@asethwright)
|
||||
|
||||
### v1.0.0, 2014-08-31
|
||||
- update readme to reflect github organization change
|
||||
- bring in linux support
|
||||
- small refactoring
|
||||
- rename plugin to tmux-battery
|
||||
- add contributors to the readme
|
||||
|
||||
### v0.0.2, 2014-06-03
|
||||
- switch to tab indentation
|
||||
- do not automatically prepend battery status
|
||||
- change format interpolation strings to more Tmux-idiomatic
|
||||
`#{battery_percentage}` and `#{battery_icon}`
|
||||
- refactoring for simplicity
|
||||
- support interpolation in `status-left` option too
|
||||
- README update
|
||||
|
||||
### v0.0.1, 2014-06-03
|
||||
- tag version 0.0.1
|
19
tmux/.tmux/plugins/tmux-battery/LICENSE.md
Normal file
@ -0,0 +1,19 @@
|
||||
Copyright (C) 2014 Bruno Sutic
|
||||
|
||||
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:
|
||||
|
||||
The above copyright notice and this permission notice shall be included
|
||||
in all copies or substantial portions of the Software.
|
||||
|
||||
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.
|
262
tmux/.tmux/plugins/tmux-battery/README.md
Normal file
@ -0,0 +1,262 @@
|
||||
# Tmux battery status
|
||||
|
||||
Enables displaying battery percentage and status icon in tmux status-right.
|
||||
|
||||
## Installation
|
||||
|
||||
In order to read the battery status, this plugin depends on having one of the following applications installed:
|
||||
- pmset (MacOS only)
|
||||
- acpi
|
||||
- upower
|
||||
- termux-battery-status
|
||||
- apm
|
||||
|
||||
In a normal situation, one of the above should be installed on your system by default and thus it should not be necessary to specifically install one of them. That being said, the `acpi` utility is currently recommended for use over `upower` where possible due to ongoing CPU usage issues.
|
||||
|
||||
### Installation with [Tmux Plugin Manager](https://github.com/tmux-plugins/tpm) (recommended)
|
||||
|
||||
Add plugin to the list of TPM plugins in `.tmux.conf`:
|
||||
|
||||
```tmux
|
||||
set -g @plugin 'tmux-plugins/tmux-battery'
|
||||
```
|
||||
|
||||
Hit `<prefix> + I` to fetch the plugin and source it.
|
||||
|
||||
If format strings are added to `status-right`, they should now be visible.
|
||||
|
||||
### Manual Installation
|
||||
|
||||
Clone the repo:
|
||||
|
||||
```shell
|
||||
git clone https://github.com/tmux-plugins/tmux-battery ~/clone/path
|
||||
```
|
||||
|
||||
Add this line to the bottom of `.tmux.conf`:
|
||||
|
||||
```tmux
|
||||
run-shell ~/clone/path/battery.tmux
|
||||
```
|
||||
|
||||
From the terminal, reload TMUX environment:
|
||||
|
||||
```shell
|
||||
tmux source-file ~/.tmux.conf
|
||||
```
|
||||
|
||||
If format strings are added to `status-right`, they should now be visible.
|
||||
|
||||
## Usage
|
||||
|
||||
Add any of the supported format strings (see below) to the `status-right` tmux option in `.tmux.conf`. Example:
|
||||
|
||||
```tmux
|
||||
set -g status-right '#{battery_status_bg} Batt: #{battery_icon} #{battery_percentage} #{battery_remain} | %a %h-%d %H:%M '
|
||||
```
|
||||
|
||||
### Supported Format Strings
|
||||
|
||||
- `#{battery_color_bg}` - will set the background color of the status bar based on the battery charge level if discharging and status otherwise
|
||||
- `#{battery_color_fg}` - will set the foreground color of the status bar based on the battery charge level if discharging and status otherwise
|
||||
- `#{battery_color_charge_bg}` - will set the background color of the status bar based solely on the battery charge level
|
||||
- `#{battery_color_charge_fg}` - will set the foreground color of the status bar based solely on the battery charge level
|
||||
- `#{battery_color_status_bg}` - will set the background color of the status bar based solely on the battery status
|
||||
- `#{battery_color_status_fg}` - will set the foreground color of the status bar based solely on the battery status
|
||||
- `#{battery_graph}` - will show battery percentage as a bar graph: ▁▂▄▆█
|
||||
- `#{battery_icon}` - will display a battery status/charge icon
|
||||
- `#{battery_icon_charge}` - will display a battery charge icon
|
||||
- `#{battery_icon_status}` - will display a battery status icon
|
||||
- `#{battery_percentage}` - will show battery percentage
|
||||
- `#{battery_remain}` - will show remaining time of battery charge\*
|
||||
|
||||
\* These format strings can be further customized via options as described below.
|
||||
|
||||
#### Options
|
||||
|
||||
`#{battery_remain}`
|
||||
|
||||
- `@batt_remain_short`: 'true' / 'false' - This will shorten the time remaining (when charging or discharging) to `~H:MM`.
|
||||
|
||||
### Defaults
|
||||
|
||||
#### Options
|
||||
|
||||
- `@batt_remain_short`: 'false'
|
||||
|
||||
#### Icons/Colors
|
||||
|
||||
By default, the following colors and icons are used. (The exact colors displayed depends on your terminal / X11 config.)
|
||||
|
||||
Please be aware that the 'level of charge' as noted below (e.g. `[80%-95%)`) uses interval notation. If you are unfamiliar with it, <a href="https://en.wikipedia.org/wiki/Bracket_(mathematics)#Intervals">check it out here</a>.
|
||||
|
||||
Also, a note about the `@batt_color_...` options: `@batt_color_..._primary_...` options are what will be displayed in the main `bg` or `fg` format strings you choose - e.g. if you use `#{battery_color_bg}`, the `@batt_color_..._primary_...` colors you choose will be the background. Likewise, the corresponding `@batt_color_..._secondary_...` color will be the foreground.
|
||||
|
||||
Level of Charge Colors:
|
||||
|
||||
- primary tier 8 \[95%-100%] (`@batt_color_charge_primary_tier8`): '#00ff00'
|
||||
- primary tier 7 \[80%-95%) (`@batt_color_charge_primary_tier7`): '#55ff00'
|
||||
- primary tier 6 \[65%-80%) (`@batt_color_charge_primary_tier6`): '#aaff00'
|
||||
- primary tier 5 \[50%-65%) (`@batt_color_charge_primary_tier5`): '#ffff00'
|
||||
- primary tier 4 \[35%-50%) (`@batt_color_charge_primary_tier4`): '#ffc000'
|
||||
- primary tier 3 \[20%-35%) (`@batt_color_charge_primary_tier3`): '#ff8000'
|
||||
- primary tier 2 (5%-20%) (`@batt_color_charge_primary_tier2`): '#ff4000'
|
||||
- primary tier 1 \[0%-5%] (`@batt_color_charge_primary_tier1`): '#ff0000'
|
||||
- secondary tier 8 \[95%-100%] (`@batt_color_charge_secondary_tier8`): 'colour0'
|
||||
- secondary tier 7 \[80%-95%) (`@batt_color_charge_secondary_tier7`): 'colour0'
|
||||
- secondary tier 6 \[65%-80%) (`@batt_color_charge_secondary_tier6`): 'colour0'
|
||||
- secondary tier 5 \[50%-65%) (`@batt_color_charge_secondary_tier5`): 'colour0'
|
||||
- secondary tier 4 \[35%-50%) (`@batt_color_charge_secondary_tier4`): 'colour0'
|
||||
- secondary tier 3 \[20%-35%) (`@batt_color_charge_secondary_tier3`): 'colour0'
|
||||
- secondary tier 2 (5%-20%) (`@batt_color_charge_secondary_tier2`): 'colour0'
|
||||
- secondary tier 1 \[0%-5%] (`@batt_color_charge_secondary_tier1`): 'colour0'
|
||||
|
||||
Status Colors:
|
||||
|
||||
- primary charged (`@batt_color_status_primary_charged`): 'colour33'
|
||||
- primary charging (`@batt_color_status_primary_charging`): 'colour33'
|
||||
- primary discharging (`@batt_color_status_primary_discharging`): 'colour14'
|
||||
- primary attached (`@batt_color_status_primary_attached`): 'colour201'
|
||||
- primary unknown (`@batt_color_status_primary_unknown`): 'colour7'
|
||||
- secondary charged (`@batt_color_status_secondary_charged`): 'colour0'
|
||||
- secondary charging (`@batt_color_status_secondary_charging`): 'colour0'
|
||||
- secondary discharging (`@batt_color_status_secondary_discharging`): 'colour0'
|
||||
- secondary attached (`@batt_color_status_secondary_attached`): 'colour0'
|
||||
- secondary unknown (`@batt_color_status_secondary_unknown`): 'colour0'
|
||||
|
||||
Level of Charge Icons:
|
||||
|
||||
- tier 8 \[95%-100%] (`@batt_icon_charge_tier8`): '█'
|
||||
- tier 7 \[80%-95%) (`@batt_icon_charge_tier7`): '▇'
|
||||
- tier 6 \[65%-80%) (`@batt_icon_charge_tier6`): '▆'
|
||||
- tier 5 \[50%-65%) (`@batt_icon_charge_tier5`): '▅'
|
||||
- tier 4 \[35%-50%) (`@batt_icon_charge_tier4`): '▄'
|
||||
- tier 3 \[20%-35%) (`@batt_icon_charge_tier3`): '▃'
|
||||
- tier 2 (5%-20%) (`@batt_icon_charge_tier2`): '▂'
|
||||
- tier 1 \[0%-5%] (`@batt_icon_charge_tier1`): '▁'
|
||||
|
||||
Status Icons:
|
||||
|
||||
- charged (`@batt_icon_status_charged`): '🔌'
|
||||
- charged - OS X (`@batt_icon_status_charged`): '🔌'
|
||||
- charging (`@batt_icon_status_charging`): '🔌'
|
||||
- discharging (`@batt_icon_status_discharging`): '🔋'
|
||||
- attached (`@batt_icon_status_attached`): '⚠️'
|
||||
- unknown (`@batt_icon_status_unknown`): '?'
|
||||
|
||||
#### Changing the Defaults
|
||||
|
||||
All efforts have been made to make sane defaults, but if you wish to change any of them, add the option to `.tmux.conf`. For example:
|
||||
|
||||
```tmux
|
||||
set -g @batt_icon_charge_tier8 '🌕'
|
||||
set -g @batt_icon_charge_tier7 '🌖'
|
||||
set -g @batt_icon_charge_tier6 '🌖'
|
||||
set -g @batt_icon_charge_tier5 '🌗'
|
||||
set -g @batt_icon_charge_tier4 '🌗'
|
||||
set -g @batt_icon_charge_tier3 '🌘'
|
||||
set -g @batt_icon_charge_tier2 '🌘'
|
||||
set -g @batt_icon_charge_tier1 '🌑'
|
||||
set -g @batt_icon_status_charged '🔋'
|
||||
set -g @batt_icon_status_charging '⚡'
|
||||
set -g @batt_icon_status_discharging '👎'
|
||||
set -g @batt_color_status_primary_charged '#3daee9'
|
||||
set -g @batt_color_status_primary_charging '#3daee9'
|
||||
```
|
||||
|
||||
Don't forget to reload the tmux environment after you do this by either hitting `<prefix> + I` if tmux battery is installed via the tmux plugin manager, or by typing `tmux source-file ~/.tmux.conf` in the terminal if tmux battery is manually installed.
|
||||
|
||||
*Warning*: The battery icon change most likely will not be instant. When you un-plug the power cord, it will take some time (15 - 60 seconds) for the icon to change. This depends on the `status-interval` tmux option. Setting it to 15 seconds should be good enough.
|
||||
|
||||
## Examples
|
||||
|
||||
These are all examples of the default plugin color and icon schemes paired with the default tmux color scheme using the following `status-right` and `status-right-length` settings in `.tmux.conf`
|
||||
|
||||
```tmux
|
||||
set -g status-right 'Colors: #{battery_color_bg}bg#[default] #{battery_color_fg}fg#[default] #{battery_color_charge_bg}charge_bg#[default] #{battery_color_charge_fg}charge_fg#[default] #{battery_color_status_bg}status_bg#[default] #{battery_color_status_fg}status_fg#[default] | Graph: #{battery_graph} | Icon: #{battery_icon} | Charge Icon: #{battery_icon_charge} | Status Icon: #{battery_icon_status} | Percent: #{battery_percentage} | Remain: #{battery_remain}'
|
||||
set -g status-right-length '150'
|
||||
```
|
||||
|
||||
Battery charging at tier 8 \[95%-100%]:<br>
|
||||

|
||||
|
||||
Battery charging at tier 7 \[80%-95%):<br>
|
||||

|
||||
|
||||
Battery charging at tier 6 \[65%-80%):<br>
|
||||

|
||||
|
||||
Battery charging at tier 5 \[50%-65%):<br>
|
||||

|
||||
|
||||
Battery charging at tier 4 \[35%-50%):<br>
|
||||

|
||||
|
||||
Battery charging at tier 3 \[20%-35%):<br>
|
||||

|
||||
|
||||
Battery charging at tier 2 (5%-20%):<br>
|
||||

|
||||
|
||||
Battery charging at tier 1 \[0%-5%]:<br>
|
||||

|
||||
|
||||
Battery discharging at tier 8 \[95%-100%]:<br>
|
||||

|
||||
|
||||
Battery discharging at tier 7 \[80%-95%):<br>
|
||||

|
||||
|
||||
Battery discharging at tier 6 \[65%-80%):<br>
|
||||

|
||||
|
||||
Battery discharging at tier 5 \[50%-65%):<br>
|
||||

|
||||
|
||||
Battery discharging at tier 4 \[35%-50%):<br>
|
||||

|
||||
|
||||
Battery discharging at tier 3 \[20%-35%):<br>
|
||||

|
||||
|
||||
Battery discharging at tier 2 (5%-20%):<br>
|
||||

|
||||
|
||||
Battery discharging at tier 1 \[0%-5%]:<br>
|
||||

|
||||
|
||||
Battery in 'attached' status:<br>
|
||||

|
||||
|
||||
Battery in an unknown status:<br>
|
||||

|
||||
|
||||
### Tmux Plugins
|
||||
|
||||
This plugin is part of the [tmux-plugins](https://github.com/tmux-plugins) organisation. Checkout plugins as [resurrect](https://github.com/tmux-plugins/tmux-resurrect), [logging](https://github.com/tmux-plugins/tmux-logging), [online status](https://github.com/tmux-plugins/tmux-online-status), and many more over at the [tmux-plugins](https://github.com/tmux-plugins) organisation page.
|
||||
|
||||
### Maintainer
|
||||
|
||||
- [Martin Beentjes](https://github.com/martinbeentjes)
|
||||
|
||||
### Contributors
|
||||
|
||||
- Adam Biggs
|
||||
- Aleksandar Djurdjic
|
||||
- Bruno Sutic
|
||||
- Caleb
|
||||
- Dan Cassidy
|
||||
- Diego Ximenes
|
||||
- Evan N-D
|
||||
- Jan Ahrens
|
||||
- Joey Geralnik
|
||||
- HyunJong (Joseph) Lee
|
||||
- Martin Beentjes
|
||||
- Mike Foley
|
||||
- Ryan Frantz
|
||||
- Seth Wright
|
||||
- Tom Levens
|
||||
|
||||
### License
|
||||
|
||||
[MIT](LICENSE.md)
|
62
tmux/.tmux/plugins/tmux-battery/battery.tmux
Executable file
@ -0,0 +1,62 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
source "$CURRENT_DIR/scripts/helpers.sh"
|
||||
|
||||
battery_interpolation=(
|
||||
"\#{battery_color_bg}"
|
||||
"\#{battery_color_fg}"
|
||||
"\#{battery_color_charge_bg}"
|
||||
"\#{battery_color_charge_fg}"
|
||||
"\#{battery_color_status_bg}"
|
||||
"\#{battery_color_status_fg}"
|
||||
"\#{battery_graph}"
|
||||
"\#{battery_icon}"
|
||||
"\#{battery_icon_charge}"
|
||||
"\#{battery_icon_status}"
|
||||
"\#{battery_percentage}"
|
||||
"\#{battery_remain}"
|
||||
)
|
||||
|
||||
battery_commands=(
|
||||
"#($CURRENT_DIR/scripts/battery_color.sh bg)"
|
||||
"#($CURRENT_DIR/scripts/battery_color.sh fg)"
|
||||
"#($CURRENT_DIR/scripts/battery_color_charge.sh bg)"
|
||||
"#($CURRENT_DIR/scripts/battery_color_charge.sh fg)"
|
||||
"#($CURRENT_DIR/scripts/battery_color_status.sh bg)"
|
||||
"#($CURRENT_DIR/scripts/battery_color_status.sh fg)"
|
||||
"#($CURRENT_DIR/scripts/battery_graph.sh)"
|
||||
"#($CURRENT_DIR/scripts/battery_icon.sh)"
|
||||
"#($CURRENT_DIR/scripts/battery_icon_charge.sh)"
|
||||
"#($CURRENT_DIR/scripts/battery_icon_status.sh)"
|
||||
"#($CURRENT_DIR/scripts/battery_percentage.sh)"
|
||||
"#($CURRENT_DIR/scripts/battery_remain.sh)"
|
||||
)
|
||||
|
||||
set_tmux_option() {
|
||||
local option="$1"
|
||||
local value="$2"
|
||||
tmux set-option -gq "$option" "$value"
|
||||
}
|
||||
|
||||
do_interpolation() {
|
||||
local all_interpolated="$1"
|
||||
for ((i=0; i<${#battery_commands[@]}; i++)); do
|
||||
all_interpolated=${all_interpolated//${battery_interpolation[$i]}/${battery_commands[$i]}}
|
||||
done
|
||||
echo "$all_interpolated"
|
||||
}
|
||||
|
||||
update_tmux_option() {
|
||||
local option="$1"
|
||||
local option_value="$(get_tmux_option "$option")"
|
||||
local new_option_value="$(do_interpolation "$option_value")"
|
||||
set_tmux_option "$option" "$new_option_value"
|
||||
}
|
||||
|
||||
main() {
|
||||
update_tmux_option "status-right"
|
||||
update_tmux_option "status-left"
|
||||
}
|
||||
main
|
After Width: | Height: | Size: 7.3 KiB |
After Width: | Height: | Size: 7.6 KiB |
After Width: | Height: | Size: 7.7 KiB |
After Width: | Height: | Size: 7.7 KiB |
After Width: | Height: | Size: 7.6 KiB |
After Width: | Height: | Size: 7.6 KiB |
After Width: | Height: | Size: 7.6 KiB |
After Width: | Height: | Size: 7.6 KiB |
After Width: | Height: | Size: 7.3 KiB |
After Width: | Height: | Size: 7.8 KiB |
After Width: | Height: | Size: 8.1 KiB |
After Width: | Height: | Size: 8.1 KiB |
After Width: | Height: | Size: 7.9 KiB |
After Width: | Height: | Size: 7.9 KiB |
After Width: | Height: | Size: 8.1 KiB |
After Width: | Height: | Size: 7.3 KiB |
After Width: | Height: | Size: 7.4 KiB |
After Width: | Height: | Size: 7.1 KiB |
23
tmux/.tmux/plugins/tmux-battery/scripts/battery_color.sh
Executable file
@ -0,0 +1,23 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
source "$CURRENT_DIR/helpers.sh"
|
||||
|
||||
print_color() {
|
||||
local plane="$1"
|
||||
local status="$2"
|
||||
if [ "$status" == "discharging" ]; then
|
||||
$CURRENT_DIR/battery_color_charge.sh "$plane"
|
||||
else
|
||||
$CURRENT_DIR/battery_color_status.sh "$plane" "$status"
|
||||
fi
|
||||
}
|
||||
|
||||
main() {
|
||||
local status="$(battery_status)"
|
||||
local plane="$1"
|
||||
print_color "$plane" "$status"
|
||||
}
|
||||
|
||||
main $@
|
98
tmux/.tmux/plugins/tmux-battery/scripts/battery_color_charge.sh
Executable file
@ -0,0 +1,98 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
source "$CURRENT_DIR/helpers.sh"
|
||||
|
||||
# script global variables
|
||||
color_charge_primary_tier8=''
|
||||
color_charge_primary_tier7=''
|
||||
color_charge_primary_tier6=''
|
||||
color_charge_primary_tier5=''
|
||||
color_charge_primary_tier4=''
|
||||
color_charge_primary_tier3=''
|
||||
color_charge_primary_tier2=''
|
||||
color_charge_primary_tier1=''
|
||||
color_charge_secondary_tier8=''
|
||||
color_charge_secondary_tier7=''
|
||||
color_charge_secondary_tier6=''
|
||||
color_charge_secondary_tier5=''
|
||||
color_charge_secondary_tier4=''
|
||||
color_charge_secondary_tier3=''
|
||||
color_charge_secondary_tier2=''
|
||||
color_charge_secondary_tier1=''
|
||||
|
||||
# script default variables
|
||||
color_charge_primary_tier8_default='#00ff00'
|
||||
color_charge_primary_tier7_default='#55ff00'
|
||||
color_charge_primary_tier6_default='#aaff00'
|
||||
color_charge_primary_tier5_default='#ffff00'
|
||||
color_charge_primary_tier4_default='#ffc000'
|
||||
color_charge_primary_tier3_default='#ff8000'
|
||||
color_charge_primary_tier2_default='#ff4000'
|
||||
color_charge_primary_tier1_default='#ff0000'
|
||||
color_charge_secondary_tier8_default='colour0'
|
||||
color_charge_secondary_tier7_default='colour0'
|
||||
color_charge_secondary_tier6_default='colour0'
|
||||
color_charge_secondary_tier5_default='colour0'
|
||||
color_charge_secondary_tier4_default='colour0'
|
||||
color_charge_secondary_tier3_default='colour0'
|
||||
color_charge_secondary_tier2_default='colour0'
|
||||
color_charge_secondary_tier1_default='colour0'
|
||||
|
||||
# colors are set as script global variables
|
||||
get_color_charge_settings() {
|
||||
color_charge_primary_tier8=$(get_tmux_option "@batt_color_charge_primary_tier8" "$color_charge_primary_tier8_default")
|
||||
color_charge_primary_tier7=$(get_tmux_option "@batt_color_charge_primary_tier7" "$color_charge_primary_tier7_default")
|
||||
color_charge_primary_tier6=$(get_tmux_option "@batt_color_charge_primary_tier6" "$color_charge_primary_tier6_default")
|
||||
color_charge_primary_tier5=$(get_tmux_option "@batt_color_charge_primary_tier5" "$color_charge_primary_tier5_default")
|
||||
color_charge_primary_tier4=$(get_tmux_option "@batt_color_charge_primary_tier4" "$color_charge_primary_tier4_default")
|
||||
color_charge_primary_tier3=$(get_tmux_option "@batt_color_charge_primary_tier3" "$color_charge_primary_tier3_default")
|
||||
color_charge_primary_tier2=$(get_tmux_option "@batt_color_charge_primary_tier2" "$color_charge_primary_tier2_default")
|
||||
color_charge_primary_tier1=$(get_tmux_option "@batt_color_charge_primary_tier1" "$color_charge_primary_tier1_default")
|
||||
color_charge_secondary_tier8=$(get_tmux_option "@batt_color_charge_secondary_tier8" "$color_charge_secondary_tier8_default")
|
||||
color_charge_secondary_tier7=$(get_tmux_option "@batt_color_charge_secondary_tier7" "$color_charge_secondary_tier7_default")
|
||||
color_charge_secondary_tier6=$(get_tmux_option "@batt_color_charge_secondary_tier6" "$color_charge_secondary_tier6_default")
|
||||
color_charge_secondary_tier5=$(get_tmux_option "@batt_color_charge_secondary_tier5" "$color_charge_secondary_tier5_default")
|
||||
color_charge_secondary_tier4=$(get_tmux_option "@batt_color_charge_secondary_tier4" "$color_charge_secondary_tier4_default")
|
||||
color_charge_secondary_tier3=$(get_tmux_option "@batt_color_charge_secondary_tier3" "$color_charge_secondary_tier3_default")
|
||||
color_charge_secondary_tier2=$(get_tmux_option "@batt_color_charge_secondary_tier2" "$color_charge_secondary_tier2_default")
|
||||
color_charge_secondary_tier1=$(get_tmux_option "@batt_color_charge_secondary_tier1" "$color_charge_secondary_tier1_default")
|
||||
}
|
||||
|
||||
print_color_charge() {
|
||||
local primary_plane="$1"
|
||||
local secondary_plane=""
|
||||
if [ "$primary_plane" == "bg" ]; then
|
||||
secondary_plane="fg"
|
||||
else
|
||||
secondary_plane="bg"
|
||||
fi
|
||||
percentage=$($CURRENT_DIR/battery_percentage.sh | sed -e 's/%//')
|
||||
if [ $percentage -ge 95 -o "$percentage" == "" ]; then
|
||||
# if percentage is empty, assume it's a desktop
|
||||
printf "#[$primary_plane=$color_charge_primary_tier8${color_charge_secondary_tier8:+",$secondary_plane=$color_charge_secondary_tier8"}]"
|
||||
elif [ $percentage -ge 80 ]; then
|
||||
printf "#[$primary_plane=$color_charge_primary_tier7${color_charge_secondary_tier7:+",$secondary_plane=$color_charge_secondary_tier7"}]"
|
||||
elif [ $percentage -ge 65 ]; then
|
||||
printf "#[$primary_plane=$color_charge_primary_tier6${color_charge_secondary_tier6:+",$secondary_plane=$color_charge_secondary_tier6"}]"
|
||||
elif [ $percentage -ge 50 ]; then
|
||||
printf "#[$primary_plane=$color_charge_primary_tier5${color_charge_secondary_tier5:+",$secondary_plane=$color_charge_secondary_tier5"}]"
|
||||
elif [ $percentage -ge 35 ]; then
|
||||
printf "#[$primary_plane=$color_charge_primary_tier4${color_charge_secondary_tier4:+",$secondary_plane=$color_charge_secondary_tier4"}]"
|
||||
elif [ $percentage -ge 20 ]; then
|
||||
printf "#[$primary_plane=$color_charge_primary_tier3${color_charge_secondary_tier3:+",$secondary_plane=$color_charge_secondary_tier3"}]"
|
||||
elif [ $percentage -gt 5 ]; then
|
||||
printf "#[$primary_plane=$color_charge_primary_tier2${color_charge_secondary_tier2:+",$secondary_plane=$color_charge_secondary_tier2"}]"
|
||||
else
|
||||
printf "#[$primary_plane=$color_charge_primary_tier1${color_charge_secondary_tier1:+",$secondary_plane=$color_charge_secondary_tier1"}]"
|
||||
fi
|
||||
}
|
||||
|
||||
main() {
|
||||
local plane="$1"
|
||||
get_color_charge_settings
|
||||
print_color_charge "$plane"
|
||||
}
|
||||
|
||||
main $@
|
74
tmux/.tmux/plugins/tmux-battery/scripts/battery_color_status.sh
Executable file
@ -0,0 +1,74 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
source "$CURRENT_DIR/helpers.sh"
|
||||
|
||||
# script global variables
|
||||
color_status_primary_charged=''
|
||||
color_status_primary_charging=''
|
||||
color_status_primary_discharging=''
|
||||
color_status_primary_attached=''
|
||||
color_status_primary_unknown=''
|
||||
color_status_secondary_charged=''
|
||||
color_status_secondary_charging=''
|
||||
color_status_secondary_discharging=''
|
||||
color_status_secondary_attached=''
|
||||
color_status_secondary_unknown=''
|
||||
|
||||
# script default variables
|
||||
color_status_primary_charged_default='colour33'
|
||||
color_status_primary_charging_default='colour33'
|
||||
color_status_primary_discharging_default='colour14'
|
||||
color_status_primary_attached_default='colour201'
|
||||
color_status_primary_unknown_default='colour7'
|
||||
color_status_secondary_charged_default='colour0'
|
||||
color_status_secondary_charging_default='colour0'
|
||||
color_status_secondary_discharging_default='colour0'
|
||||
color_status_secondary_attached_default='colour0'
|
||||
color_status_secondary_unknown_default='colour0'
|
||||
|
||||
# colors are set as script global variables
|
||||
get_color_status_settings() {
|
||||
color_status_primary_charged=$(get_tmux_option "@batt_color_status_primary_charged" "$color_status_primary_charged_default")
|
||||
color_status_primary_charging=$(get_tmux_option "@batt_color_status_primary_charging" "$color_status_primary_charging_default")
|
||||
color_status_primary_discharging=$(get_tmux_option "@batt_color_status_primary_discharging" "$color_status_primary_discharging_default")
|
||||
color_status_primary_attached=$(get_tmux_option "@batt_color_status_primary_attached" "$color_status_primary_attached_default")
|
||||
color_status_primary_unknown=$(get_tmux_option "@batt_color_status_primary_unknown" "$color_status_primary_unknown_default")
|
||||
color_status_secondary_charged=$(get_tmux_option "@batt_color_status_secondary_charged" "$color_status_secondary_charged_default")
|
||||
color_status_secondary_charging=$(get_tmux_option "@batt_color_status_secondary_charging" "$color_status_secondary_charging_default")
|
||||
color_status_secondary_discharging=$(get_tmux_option "@batt_color_status_secondary_discharging" "$color_status_secondary_discharging_default")
|
||||
color_status_secondary_attached=$(get_tmux_option "@batt_color_status_secondary_attached" "$color_status_secondary_attached_default")
|
||||
color_status_secondary_unknown=$(get_tmux_option "@batt_color_status_secondary_unknown" "$color_status_secondary_unknown_default")
|
||||
}
|
||||
|
||||
print_color_status() {
|
||||
local plane_primary="$1"
|
||||
local plane_secondary=""
|
||||
if [ "$plane_primary" == "bg" ]; then
|
||||
plane_secondary="fg"
|
||||
else
|
||||
plane_secondary="bg"
|
||||
fi
|
||||
local status="$2"
|
||||
if [[ $status =~ (charged) || $status =~ (full) ]]; then
|
||||
printf "#[$plane_primary=$color_status_primary_charged${color_status_secondary_charged:+",$plane_secondary=$color_status_secondary_charged"}]"
|
||||
elif [[ $status =~ (^charging) ]]; then
|
||||
printf "#[$plane_primary=$color_status_primary_charging${color_status_secondary_charging:+",$plane_secondary=$color_status_secondary_charging"}]"
|
||||
elif [[ $status =~ (^discharging) ]]; then
|
||||
printf "#[$plane_primary=$color_status_primary_discharging${color_status_secondary_discharging:+",$plane_secondary=$color_status_secondary_discharging"}]"
|
||||
elif [[ $status =~ (attached) ]]; then
|
||||
printf "#[$plane_primary=$color_status_primary_attached${color_status_secondary_attached:+",$plane_secondary=$color_status_secondary_attached"}]"
|
||||
else
|
||||
printf "#[$plane_primary=$color_status_primary_unknown${color_status_secondary_unknown:+",$plane_secondary=$color_status_secondary_unknown"}]"
|
||||
fi
|
||||
}
|
||||
|
||||
main() {
|
||||
local plane="$1"
|
||||
local status=${2:-$(battery_status)}
|
||||
get_color_status_settings
|
||||
print_color_status "$plane" "$status"
|
||||
}
|
||||
|
||||
main $@
|
45
tmux/.tmux/plugins/tmux-battery/scripts/battery_graph.sh
Executable file
@ -0,0 +1,45 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
source "$CURRENT_DIR/helpers.sh"
|
||||
|
||||
print_graph() {
|
||||
local percentage=$1
|
||||
if [ $percentage -gt 5 ]; then
|
||||
printf "▁"
|
||||
else
|
||||
printf " "
|
||||
fi
|
||||
if [ $percentage -ge 25 ]; then
|
||||
printf "▂"
|
||||
else
|
||||
printf " "
|
||||
fi
|
||||
if [ $percentage -ge 50 ]; then
|
||||
printf "▄"
|
||||
else
|
||||
printf " "
|
||||
fi
|
||||
if [ $percentage -ge 75 ]; then
|
||||
printf "▆"
|
||||
else
|
||||
printf " "
|
||||
fi
|
||||
if [ $percentage -ge 95 ]; then
|
||||
printf "█"
|
||||
else
|
||||
printf " "
|
||||
echo "▇"
|
||||
fi
|
||||
}
|
||||
|
||||
main() {
|
||||
local percentage=$($CURRENT_DIR/battery_percentage.sh)
|
||||
if [ "$(uname)" == "OpenBSD" ]; then
|
||||
print_graph ${percentage}
|
||||
else
|
||||
print_graph ${percentage%?}
|
||||
fi
|
||||
}
|
||||
main
|
21
tmux/.tmux/plugins/tmux-battery/scripts/battery_icon.sh
Executable file
@ -0,0 +1,21 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
source "$CURRENT_DIR/helpers.sh"
|
||||
|
||||
print_icon() {
|
||||
local status=$1
|
||||
if [ "$status" == "discharging" ]; then
|
||||
$CURRENT_DIR/battery_icon_charge.sh
|
||||
else
|
||||
$CURRENT_DIR/battery_icon_status.sh "$status"
|
||||
fi
|
||||
}
|
||||
|
||||
main() {
|
||||
local status=$(battery_status)
|
||||
print_icon "$status"
|
||||
}
|
||||
|
||||
main
|
66
tmux/.tmux/plugins/tmux-battery/scripts/battery_icon_charge.sh
Executable file
@ -0,0 +1,66 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
source "$CURRENT_DIR/helpers.sh"
|
||||
|
||||
# script global variables
|
||||
icon_charge_tier8=''
|
||||
icon_charge_tier7=''
|
||||
icon_charge_tier6=''
|
||||
icon_charge_tier5=''
|
||||
icon_charge_tier4=''
|
||||
icon_charge_tier3=''
|
||||
icon_charge_tier2=''
|
||||
icon_charge_tier1=''
|
||||
|
||||
# script default variables
|
||||
icon_charge_tier8_default='█'
|
||||
icon_charge_tier7_default='▇'
|
||||
icon_charge_tier6_default='▆'
|
||||
icon_charge_tier5_default='▅'
|
||||
icon_charge_tier4_default='▄'
|
||||
icon_charge_tier3_default='▃'
|
||||
icon_charge_tier2_default='▂'
|
||||
icon_charge_tier1_default='▁'
|
||||
|
||||
# icons are set as script global variables
|
||||
get_icon_charge_settings() {
|
||||
icon_charge_tier8=$(get_tmux_option "@batt_icon_charge_tier8" "$icon_charge_tier8_default")
|
||||
icon_charge_tier7=$(get_tmux_option "@batt_icon_charge_tier7" "$icon_charge_tier7_default")
|
||||
icon_charge_tier6=$(get_tmux_option "@batt_icon_charge_tier6" "$icon_charge_tier6_default")
|
||||
icon_charge_tier5=$(get_tmux_option "@batt_icon_charge_tier5" "$icon_charge_tier5_default")
|
||||
icon_charge_tier4=$(get_tmux_option "@batt_icon_charge_tier4" "$icon_charge_tier4_default")
|
||||
icon_charge_tier3=$(get_tmux_option "@batt_icon_charge_tier3" "$icon_charge_tier3_default")
|
||||
icon_charge_tier2=$(get_tmux_option "@batt_icon_charge_tier2" "$icon_charge_tier2_default")
|
||||
icon_charge_tier1=$(get_tmux_option "@batt_icon_charge_tier1" "$icon_charge_tier1_default")
|
||||
}
|
||||
|
||||
print_icon_charge() {
|
||||
percentage=$($CURRENT_DIR/battery_percentage.sh | sed -e 's/%//')
|
||||
if [ $percentage -ge 95 -o "$percentage" == "" ]; then
|
||||
# if percentage is empty, assume it's a desktop
|
||||
printf "$icon_charge_tier8"
|
||||
elif [ $percentage -ge 80 ]; then
|
||||
printf "$icon_charge_tier7"
|
||||
elif [ $percentage -ge 65 ]; then
|
||||
printf "$icon_charge_tier6"
|
||||
elif [ $percentage -ge 50 ]; then
|
||||
printf "$icon_charge_tier5"
|
||||
elif [ $percentage -ge 35 ]; then
|
||||
printf "$icon_charge_tier4"
|
||||
elif [ $percentage -ge 20 ]; then
|
||||
printf "$icon_charge_tier3"
|
||||
elif [ $percentage -gt 5 ]; then
|
||||
printf "$icon_charge_tier2"
|
||||
else
|
||||
printf "$icon_charge_tier1"
|
||||
fi
|
||||
}
|
||||
|
||||
main() {
|
||||
get_icon_charge_settings
|
||||
print_icon_charge
|
||||
}
|
||||
|
||||
main
|
61
tmux/.tmux/plugins/tmux-battery/scripts/battery_icon_status.sh
Executable file
@ -0,0 +1,61 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
source "$CURRENT_DIR/helpers.sh"
|
||||
|
||||
# script global variables
|
||||
icon_status_charged=''
|
||||
icon_status_charging=''
|
||||
icon_status_discharging=''
|
||||
icon_status_attached=''
|
||||
icon_status_unknown=''
|
||||
|
||||
# script default variables
|
||||
icon_status_charged_default='🔌'
|
||||
icon_status_charged_default_osx='🔌'
|
||||
icon_status_charging_default='🔌'
|
||||
icon_status_discharging_default='🔋'
|
||||
icon_status_attached_default='⚠️'
|
||||
icon_status_unknown_default='?'
|
||||
|
||||
# determine which charged_default variable to use
|
||||
get_icon_status_charged_default() {
|
||||
if is_osx; then
|
||||
printf "$icon_status_charged_default_osx"
|
||||
else
|
||||
printf "$icon_status_charged_default"
|
||||
fi
|
||||
}
|
||||
|
||||
# icons are set as script global variables
|
||||
get_icon_status_settings() {
|
||||
icon_status_charged=$(get_tmux_option "@batt_icon_status_charged" "$(get_icon_status_charged_default)")
|
||||
icon_status_charging=$(get_tmux_option "@batt_icon_status_charging" "$icon_status_charging_default")
|
||||
icon_status_discharging=$(get_tmux_option "@batt_icon_status_discharging" "$icon_status_discharging_default")
|
||||
icon_status_attached=$(get_tmux_option "@batt_icon_status_attached" "$icon_status_attached_default")
|
||||
icon_status_unknown=$(get_tmux_option "@batt_icon_status_unknown" "$icon_status_unknown_default")
|
||||
}
|
||||
|
||||
print_icon_status() {
|
||||
local status=$1
|
||||
if [[ $status =~ (charged) || $status =~ (full) ]]; then
|
||||
printf "$icon_status_charged"
|
||||
elif [[ $status =~ (^charging) ]]; then
|
||||
printf "$icon_status_charging"
|
||||
elif [[ $status =~ (^discharging) ]]; then
|
||||
printf "$icon_status_discharging"
|
||||
elif [[ $status =~ (attached) ]]; then
|
||||
printf "$icon_status_attached"
|
||||
else
|
||||
printf "$icon_status_unknown"
|
||||
fi
|
||||
}
|
||||
|
||||
main() {
|
||||
get_icon_status_settings
|
||||
local status=${1:-$(battery_status)}
|
||||
print_icon_status "$status"
|
||||
}
|
||||
|
||||
main
|
45
tmux/.tmux/plugins/tmux-battery/scripts/battery_percentage.sh
Executable file
@ -0,0 +1,45 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
source "$CURRENT_DIR/helpers.sh"
|
||||
|
||||
print_battery_percentage() {
|
||||
# percentage displayed in the 2nd field of the 2nd row
|
||||
if is_wsl; then
|
||||
local battery
|
||||
battery=$(find /sys/class/power_supply/*/capacity | tail -n1)
|
||||
cat "$battery"
|
||||
elif command_exists "pmset"; then
|
||||
pmset -g batt | grep -o "[0-9]\{1,3\}%"
|
||||
elif command_exists "acpi"; then
|
||||
acpi -b | grep -m 1 -Eo "[0-9]+%"
|
||||
elif command_exists "upower"; then
|
||||
# use DisplayDevice if available otherwise battery
|
||||
local battery=$(upower -e | grep -E 'battery|DisplayDevice'| tail -n1)
|
||||
if [ -z "$battery" ]; then
|
||||
return
|
||||
fi
|
||||
local percentage=$(upower -i $battery | awk '/percentage:/ {print $2}')
|
||||
if [ "$percentage" ]; then
|
||||
echo ${percentage%.*%}
|
||||
return
|
||||
fi
|
||||
local energy
|
||||
local energy_full
|
||||
energy=$(upower -i $battery | awk -v nrg="$energy" '/energy:/ {print nrg+$2}')
|
||||
energy_full=$(upower -i $battery | awk -v nrgfull="$energy_full" '/energy-full:/ {print nrgfull+$2}')
|
||||
if [ -n "$energy" ] && [ -n "$energy_full" ]; then
|
||||
echo $energy $energy_full | awk '{printf("%d%%", ($1/$2)*100)}'
|
||||
fi
|
||||
elif command_exists "termux-battery-status"; then
|
||||
termux-battery-status | jq -r '.percentage' | awk '{printf("%d%%", $1)}'
|
||||
elif command_exists "apm"; then
|
||||
apm -l
|
||||
fi
|
||||
}
|
||||
|
||||
main() {
|
||||
print_battery_percentage
|
||||
}
|
||||
main
|
130
tmux/.tmux/plugins/tmux-battery/scripts/battery_remain.sh
Executable file
@ -0,0 +1,130 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
source "$CURRENT_DIR/helpers.sh"
|
||||
|
||||
short=false
|
||||
|
||||
get_remain_settings() {
|
||||
short=$(get_tmux_option "@batt_remain_short" false)
|
||||
}
|
||||
|
||||
battery_discharging() {
|
||||
local status="$(battery_status)"
|
||||
[[ $status =~ (discharging) ]]
|
||||
}
|
||||
|
||||
battery_charged() {
|
||||
local status="$(battery_status)"
|
||||
[[ $status =~ (charged) || $status =~ (full) ]]
|
||||
}
|
||||
|
||||
|
||||
convertmins() {
|
||||
((h=${1}/60))
|
||||
((m=${1}%60))
|
||||
printf "%02d:%02d\n" $h $m $s
|
||||
}
|
||||
|
||||
apm_battery_remaining_time() {
|
||||
local remaining_time="$(convertmins $(apm -m))"
|
||||
if battery_discharging; then
|
||||
if $short; then
|
||||
echo $remaining_time | awk '{printf "~%s", $1}'
|
||||
else
|
||||
echo $remaining_time | awk '{printf "- %s left", $1}'
|
||||
fi
|
||||
elif battery_charged; then
|
||||
if $short; then
|
||||
echo $remaining_time | awk '{printf "charged", $1}'
|
||||
else
|
||||
echo $remaining_time | awk '{printf "fully charged", $1}'
|
||||
fi
|
||||
else
|
||||
echo "charging"
|
||||
fi
|
||||
}
|
||||
|
||||
pmset_battery_remaining_time() {
|
||||
local status="$(pmset -g batt)"
|
||||
if echo $status | grep 'no estimate' >/dev/null 2>&1; then
|
||||
if $short; then
|
||||
echo '~?:??'
|
||||
else
|
||||
echo '- Calculating estimate...'
|
||||
fi
|
||||
else
|
||||
local remaining_time="$(echo $status | grep -o '[0-9]\{1,2\}:[0-9]\{1,2\}')"
|
||||
if battery_discharging; then
|
||||
if $short; then
|
||||
echo $remaining_time | awk '{printf "~%s", $1}'
|
||||
else
|
||||
echo $remaining_time | awk '{printf "- %s left", $1}'
|
||||
fi
|
||||
elif battery_charged; then
|
||||
if $short; then
|
||||
echo $remaining_time | awk '{printf "charged", $1}'
|
||||
else
|
||||
echo $remaining_time | awk '{printf "fully charged", $1}'
|
||||
fi
|
||||
else
|
||||
if $short; then
|
||||
echo $remaining_time | awk '{printf "~%s", $1}'
|
||||
else
|
||||
echo $remaining_time | awk '{printf "- %s till full", $1}'
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
upower_battery_remaining_time() {
|
||||
battery=$(upower -e | grep -E 'battery|DisplayDevice'| tail -n1)
|
||||
if battery_discharging; then
|
||||
local remaining_time
|
||||
remaining_time=$(upower -i "$battery" | grep -E '(remain|time to empty)')
|
||||
if $short; then
|
||||
echo "$remaining_time" | awk '{printf "%s %s", $(NF-1), $(NF)}'
|
||||
else
|
||||
echo "$remaining_time" | awk '{printf "%s %s left", $(NF-1), $(NF)}'
|
||||
fi
|
||||
elif battery_charged; then
|
||||
if $short; then
|
||||
echo ""
|
||||
else
|
||||
echo "charged"
|
||||
fi
|
||||
else
|
||||
local remaining_time
|
||||
remaining_time=$(upower -i "$battery" | grep -E 'time to full')
|
||||
if $short; then
|
||||
echo "$remaining_time" | awk '{printf "%s %s", $(NF-1), $(NF)}'
|
||||
else
|
||||
echo "$remaining_time" | awk '{printf "%s %s to full", $(NF-1), $(NF)}'
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
acpi_battery_remaining_time() {
|
||||
acpi -b | grep -m 1 -Eo "[0-9]+:[0-9]+:[0-9]+"
|
||||
}
|
||||
|
||||
print_battery_remain() {
|
||||
if is_wsl; then
|
||||
echo "?" # currently unsupported on WSL
|
||||
elif command_exists "pmset"; then
|
||||
pmset_battery_remaining_time
|
||||
elif command_exists "acpi"; then
|
||||
acpi_battery_remaining_time
|
||||
elif command_exists "upower"; then
|
||||
upower_battery_remaining_time
|
||||
elif command_exists "apm"; then
|
||||
apm_battery_remaining_time
|
||||
fi
|
||||
}
|
||||
|
||||
main() {
|
||||
get_remain_settings
|
||||
print_battery_remain
|
||||
}
|
||||
main
|
50
tmux/.tmux/plugins/tmux-battery/scripts/battery_status_bg.sh
Executable file
@ -0,0 +1,50 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
source "$CURRENT_DIR/helpers.sh"
|
||||
|
||||
color_full_charge_default="#[bg=green]"
|
||||
color_high_charge_default="#[bg=yellow]"
|
||||
color_medium_charge_default="#[bg=colour208]" # orange
|
||||
color_low_charge_default="#[bg=red]"
|
||||
color_charging_default="#[bg=green]"
|
||||
|
||||
color_full_charge=""
|
||||
color_high_charge=""
|
||||
color_medium_charge=""
|
||||
color_low_charge=""
|
||||
color_charging=""
|
||||
|
||||
get_charge_color_settings() {
|
||||
color_full_charge=$(get_tmux_option "@batt_color_full_charge" "$color_full_charge_default")
|
||||
color_high_charge=$(get_tmux_option "@batt_color_high_charge" "$color_high_charge_default")
|
||||
color_medium_charge=$(get_tmux_option "@batt_color_medium_charge" "$color_medium_charge_default")
|
||||
color_low_charge=$(get_tmux_option "@batt_color_low_charge" "$color_low_charge_default")
|
||||
color_charging=$(get_tmux_option "@batt_color_charging" "$color_charging_default")
|
||||
}
|
||||
|
||||
print_battery_status_bg() {
|
||||
# Call `battery_percentage.sh`.
|
||||
percentage=$($CURRENT_DIR/battery_percentage.sh | sed -e 's/%//')
|
||||
status=$(battery_status | awk '{print $1;}')
|
||||
if [ $status == 'charging' ]; then
|
||||
printf $color_charging
|
||||
elif [ $percentage -eq 100 ]; then
|
||||
printf $color_full_charge
|
||||
elif [ $percentage -le 99 -a $percentage -ge 51 ];then
|
||||
printf $color_high_charge
|
||||
elif [ $percentage -le 50 -a $percentage -ge 16 ];then
|
||||
printf $color_medium_charge
|
||||
elif [ "$percentage" == "" ];then
|
||||
printf $color_full_charge_default # assume it's a desktop
|
||||
else
|
||||
printf $color_low_charge
|
||||
fi
|
||||
}
|
||||
|
||||
main() {
|
||||
get_charge_color_settings
|
||||
print_battery_status_bg
|
||||
}
|
||||
main
|
50
tmux/.tmux/plugins/tmux-battery/scripts/battery_status_fg.sh
Executable file
@ -0,0 +1,50 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
source "$CURRENT_DIR/helpers.sh"
|
||||
|
||||
color_full_charge_default="#[fg=green]"
|
||||
color_high_charge_default="#[fg=yellow]"
|
||||
color_medium_charge_default="#[fg=colour208]" # orange
|
||||
color_low_charge_default="#[fg=red]"
|
||||
color_charging_default="#[fg=green]"
|
||||
|
||||
color_full_charge=""
|
||||
color_high_charge=""
|
||||
color_medium_charge=""
|
||||
color_low_charge=""
|
||||
color_charging=""
|
||||
|
||||
get_charge_color_settings() {
|
||||
color_full_charge=$(get_tmux_option "@batt_color_full_charge" "$color_full_charge_default")
|
||||
color_high_charge=$(get_tmux_option "@batt_color_high_charge" "$color_high_charge_default")
|
||||
color_medium_charge=$(get_tmux_option "@batt_color_medium_charge" "$color_medium_charge_default")
|
||||
color_low_charge=$(get_tmux_option "@batt_color_low_charge" "$color_low_charge_default")
|
||||
color_charging=$(get_tmux_option "@batt_color_charging" "$color_charging_default")
|
||||
}
|
||||
|
||||
print_battery_status_fg() {
|
||||
# Call `battery_percentage.sh`.
|
||||
percentage=$($CURRENT_DIR/battery_percentage.sh | sed -e 's/%//')
|
||||
status=$(battery_status | awk '{print $1;}')
|
||||
if [ $status == 'charging' ]; then
|
||||
printf $color_charging
|
||||
elif [ $percentage -eq 100 ]; then
|
||||
printf $color_full_charge
|
||||
elif [ $percentage -le 99 -a $percentage -ge 51 ];then
|
||||
printf $color_high_charge
|
||||
elif [ $percentage -le 50 -a $percentage -ge 16 ];then
|
||||
printf $color_medium_charge
|
||||
elif [ "$percentage" == "" ];then
|
||||
printf $color_full_charge_default # assume it's a desktop
|
||||
else
|
||||
printf $color_low_charge
|
||||
fi
|
||||
}
|
||||
|
||||
main() {
|
||||
get_charge_color_settings
|
||||
print_battery_status_fg
|
||||
}
|
||||
main
|
63
tmux/.tmux/plugins/tmux-battery/scripts/helpers.sh
Normal file
@ -0,0 +1,63 @@
|
||||
get_tmux_option() {
|
||||
local option="$1"
|
||||
local default_value="$2"
|
||||
local option_value="$(tmux show-option -gqv "$option")"
|
||||
if [ -z "$option_value" ]; then
|
||||
echo "$default_value"
|
||||
else
|
||||
echo "$option_value"
|
||||
fi
|
||||
}
|
||||
|
||||
is_osx() {
|
||||
[ $(uname) == "Darwin" ]
|
||||
}
|
||||
|
||||
is_chrome() {
|
||||
chrome="/sys/class/chromeos/cros_ec"
|
||||
if [ -d "$chrome" ]; then
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
is_wsl() {
|
||||
version=$(</proc/version)
|
||||
if [[ "$version" == *"Microsoft"* || "$version" == *"microsoft"* ]]; then
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
command_exists() {
|
||||
local command="$1"
|
||||
type "$command" >/dev/null 2>&1
|
||||
}
|
||||
|
||||
battery_status() {
|
||||
if is_wsl; then
|
||||
local battery
|
||||
battery=$(find /sys/class/power_supply/*/status | tail -n1)
|
||||
awk '{print tolower($0);}' "$battery"
|
||||
elif command_exists "pmset"; then
|
||||
pmset -g batt | awk -F '; *' 'NR==2 { print $2 }'
|
||||
elif command_exists "acpi"; then
|
||||
acpi -b | awk '{gsub(/,/, ""); print tolower($3); exit}'
|
||||
elif command_exists "upower"; then
|
||||
local battery
|
||||
battery=$(upower -e | grep -E 'battery|DisplayDevice'| tail -n1)
|
||||
upower -i $battery | awk '/state/ {print $2}'
|
||||
elif command_exists "termux-battery-status"; then
|
||||
termux-battery-status | jq -r '.status' | awk '{printf("%s%", tolower($1))}'
|
||||
elif command_exists "apm"; then
|
||||
local battery
|
||||
battery=$(apm -a)
|
||||
if [ $battery -eq 0 ]; then
|
||||
echo "discharging"
|
||||
elif [ $battery -eq 1 ]; then
|
||||
echo "charging"
|
||||
fi
|
||||
fi
|
||||
}
|
19
tmux/.tmux/plugins/tmux-cowboy/LICENSE.md
Normal file
@ -0,0 +1,19 @@
|
||||
Copyright (C) Bruno Sutic
|
||||
|
||||
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:
|
||||
|
||||
The above copyright notice and this permission notice shall be included
|
||||
in all copies or substantial portions of the Software.
|
||||
|
||||
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.
|
24
tmux/.tmux/plugins/tmux-cowboy/README.md
Normal file
@ -0,0 +1,24 @@
|
||||
# tmux-cowboy
|
||||
|
||||
~~Just kill that damned stale process!~~ Send a signal to a process running
|
||||
inside a current pane.
|
||||
|
||||
Useful when you're annoyed by the stale program and just want to get rid of it.
|
||||
|
||||
NOTE: this plugin calls a `kill -9 <pid>` command and that's potentially
|
||||
dangerous. Use this plugin at your own responsibility. That said, I'm using
|
||||
this on my personal computer. If there are bugs I'll be the first to know.
|
||||
|
||||
### Key bindings
|
||||
|
||||
- <kbd>prefix</kbd> <kbd> * </kbd> - end the process running in the current
|
||||
pane with `kill -9`
|
||||
|
||||
### FAQ
|
||||
|
||||
Q: What's with the name? Why "cowboy"?<br/>
|
||||
A: Because you go pew-pew killing those bad processes.
|
||||
|
||||
### License
|
||||
|
||||
[MIT](LICENSE.md)
|
9
tmux/.tmux/plugins/tmux-cowboy/cowboy.tmux
Executable file
@ -0,0 +1,9 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
SCRIPTS_DIR="${CURRENT_DIR}/scripts"
|
||||
|
||||
main() {
|
||||
tmux bind-key "*" run-shell "$SCRIPTS_DIR/kill.sh KILL"
|
||||
}
|
||||
main
|
26
tmux/.tmux/plugins/tmux-cowboy/scripts/kill.sh
Executable file
@ -0,0 +1,26 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
SIGNAL="${1:-KILL}"
|
||||
|
||||
pane_pid() {
|
||||
tmux display-message -p "#{pane_pid}"
|
||||
}
|
||||
|
||||
pid() {
|
||||
local pane_pid="$(pane_pid)"
|
||||
|
||||
ps -ao "ppid pid" |
|
||||
sed "s/^ *//" |
|
||||
grep "^${pane_pid}" |
|
||||
cut -d' ' -f2- |
|
||||
head -n 1
|
||||
}
|
||||
|
||||
main() {
|
||||
local pid="$(pid)"
|
||||
|
||||
if [ -n "$pid" ]; then
|
||||
kill -${SIGNAL} $pid
|
||||
fi
|
||||
}
|
||||
main
|
16
tmux/.tmux/plugins/tmux-cpu/.editorconfig
Normal file
@ -0,0 +1,16 @@
|
||||
# EditorConfig is awesome: https://EditorConfig.org
|
||||
|
||||
# top-most EditorConfig file
|
||||
root = true
|
||||
|
||||
# Unix-style newlines with a newline ending every file
|
||||
[*]
|
||||
end_of_line = lf
|
||||
insert_final_newline = true
|
||||
charset = utf-8
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
# 2 space indentation
|
||||
[*.{sh,tmux}]
|
||||
indent_style = space
|
||||
indent_size = 2
|
2
tmux/.tmux/plugins/tmux-cpu/.mailmap
Normal file
@ -0,0 +1,2 @@
|
||||
Camille TJHOA <camille.tjhoa@outlook.com>
|
||||
Yuichi Kiri <kiririmode@gmail.com>
|
22
tmux/.tmux/plugins/tmux-cpu/LICENSE
Normal file
@ -0,0 +1,22 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 ctjhoa
|
||||
|
||||
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:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
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.
|
||||
|
170
tmux/.tmux/plugins/tmux-cpu/README.md
Normal file
@ -0,0 +1,170 @@
|
||||
# Tmux CPU and GPU status
|
||||
|
||||
Enables displaying CPU and GPU information in Tmux `status-right` and `status-left`.
|
||||
Configurable percentage and icon display.
|
||||
|
||||
## Installation
|
||||
### Installation with [Tmux Plugin Manager](https://github.com/tmux-plugins/tpm) (recommended)
|
||||
|
||||
Add plugin to the list of TPM plugins in `.tmux.conf`:
|
||||
|
||||
```shell
|
||||
set -g @plugin 'tmux-plugins/tmux-cpu'
|
||||
```
|
||||
|
||||
Hit `prefix + I` to fetch the plugin and source it.
|
||||
|
||||
If format strings are added to `status-right`, they should now be visible.
|
||||
|
||||
### Manual Installation
|
||||
|
||||
Clone the repo:
|
||||
|
||||
```shell
|
||||
$ git clone https://github.com/tmux-plugins/tmux-cpu ~/clone/path
|
||||
```
|
||||
|
||||
Add this line to the bottom of `.tmux.conf`:
|
||||
|
||||
```shell
|
||||
run-shell ~/clone/path/cpu.tmux
|
||||
```
|
||||
|
||||
Reload TMUX environment:
|
||||
|
||||
```shell
|
||||
# type this in terminal
|
||||
$ tmux source-file ~/.tmux.conf
|
||||
```
|
||||
|
||||
If format strings are added to `status-right`, they should now be visible.
|
||||
|
||||
### Optional requirements (Linux, BSD, OSX)
|
||||
|
||||
- `iostat` or `sar` are the best way to get an accurate CPU percentage.
|
||||
A fallback is included using `ps -aux` but could be inaccurate.
|
||||
- `free` is used for obtaining system RAM status.
|
||||
- `lm-sensors` is used for CPU temperature.
|
||||
- `nvidia-smi` is required for GPU information.
|
||||
For OSX, `cuda-smi` is required instead (but only shows GPU memory use rather than load).
|
||||
If "No GPU" is displayed, it means the script was not able to find `nvidia-smi`/`cuda-smi`.
|
||||
Please make sure the appropriate command is installed and in the `$PATH`.
|
||||
|
||||
## Usage
|
||||
|
||||
Add any of the supported format strings (see below) to the existing `status-right` tmux option.
|
||||
Example:
|
||||
|
||||
```shell
|
||||
# in .tmux.conf
|
||||
set -g status-right '#{cpu_bg_color} CPU: #{cpu_icon} #{cpu_percentage} | %a %h-%d %H:%M '
|
||||
```
|
||||
|
||||
### Supported Options
|
||||
|
||||
This is done by introducing 12 new format strings that can be added to
|
||||
`status-right` option:
|
||||
|
||||
- `#{cpu_icon}` - will display a CPU status icon
|
||||
- `#{cpu_percentage}` - will show CPU percentage (averaged across cores)
|
||||
- `#{cpu_bg_color}` - will change the background color based on the CPU percentage
|
||||
- `#{cpu_fg_color}` - will change the foreground color based on the CPU percentage
|
||||
- `#{ram_icon}` - will display a RAM status icon
|
||||
- `#{ram_percentage}` - will show RAM percentage (averaged across cores)
|
||||
- `#{ram_bg_color}` - will change the background color based on the RAM percentage
|
||||
- `#{ram_fg_color}` - will change the foreground color based on the RAM percentage
|
||||
- `#{cpu_temp_icon}` - will display a CPU temperature status icon
|
||||
- `#{cpu_temp}` - will show CPU temperature (averaged across cores)
|
||||
- `#{cpu_temp_bg_color}` - will change the background color based on the CPU temperature
|
||||
- `#{cpu_temp_fg_color}` - will change the foreground color based on the CPU temperature
|
||||
|
||||
GPU equivalents also exist:
|
||||
|
||||
- `#{gpu_icon}` - will display a GPU status icon
|
||||
- `#{gpu_percentage}` - will show GPU percentage (averaged across devices)
|
||||
- `#{gpu_bg_color}` - will change the background color based on the GPU percentage
|
||||
- `#{gpu_fg_color}` - will change the foreground color based on the GPU percentage
|
||||
- `#{gram_icon}` - will display a GPU RAM status icon
|
||||
- `#{gram_percentage}` - will show GPU RAM percentage (total across devices)
|
||||
- `#{gram_bg_color}` - will change the background color based on the GPU RAM percentage
|
||||
- `#{gram_fg_color}` - will change the foreground color based on the GPU RAM percentage
|
||||
- `#{gpu_temp_icon}` - will display a GPU temperature status icon
|
||||
- `#{gpu_temp}` - will show GPU temperature (average across devices)
|
||||
- `#{gpu_temp_bg_color}` - will change the background color based on the GPU temperature
|
||||
- `#{gpu_temp_fg_color}` - will change the foreground color based on the GPU temperature
|
||||
|
||||
## Examples
|
||||
|
||||
CPU usage lower than 30%:<br/>
|
||||

|
||||

|
||||

|
||||
|
||||
CPU usage between 30% and 80%:<br/>
|
||||

|
||||

|
||||

|
||||
|
||||
CPU usage higher than 80%:<br/>
|
||||

|
||||

|
||||

|
||||
|
||||
## Customization
|
||||
|
||||
Here are all available options with their default values:
|
||||
|
||||
```shell
|
||||
@cpu_low_icon "=" # icon when cpu is low
|
||||
@cpu_medium_icon "≡" # icon when cpu is medium
|
||||
@cpu_high_icon "≣" # icon when cpu is high
|
||||
|
||||
@cpu_low_fg_color "" # foreground color when cpu is low
|
||||
@cpu_medium_fg_color "" # foreground color when cpu is medium
|
||||
@cpu_high_fg_color "" # foreground color when cpu is high
|
||||
|
||||
@cpu_low_bg_color "#[bg=green]" # background color when cpu is low
|
||||
@cpu_medium_bg_color "#[bg=yellow]" # background color when cpu is medium
|
||||
@cpu_high_bg_color "#[bg=red]" # background color when cpu is high
|
||||
|
||||
@cpu_percentage_format "%3.1f%%" # printf format to use to display percentage
|
||||
|
||||
@cpu_medium_thresh "30" # medium percentage threshold
|
||||
@cpu_high_thresh "80" # high percentage threshold
|
||||
|
||||
@ram_(low_icon,high_bg_color,etc...) # same defaults as above
|
||||
|
||||
@cpu_temp_format "%2.0f" # printf format to use to display temperature
|
||||
@cpu_temp_unit "C" # supports C & F
|
||||
|
||||
@cpu_temp_medium_thresh "80" # medium temperature threshold
|
||||
@cpu_temp_high_thresh "90" # high temperature threshold
|
||||
|
||||
@cpu_temp_(low_icon,high_bg_color,etc...) # same defaults as above
|
||||
```
|
||||
|
||||
All `@cpu_*` options are valid with `@gpu_*` (except `@cpu_*_thresh` which apply to both CPU and GPU). Additionally, `@ram_*` options become `@gram_*` for GPU equivalents.
|
||||
|
||||
Note that these colors depend on your terminal / X11 config.
|
||||
|
||||
You can can customize each one of these options in your `.tmux.conf`, for example:
|
||||
|
||||
```shell
|
||||
set -g @cpu_low_fg_color "#[fg=#00ff00]"
|
||||
set -g @cpu_percentage_format "%5.1f%%" # Add left padding
|
||||
```
|
||||
|
||||
Don't forget to reload the tmux environment (`$ tmux source-file ~/.tmux.conf`) after you do this.
|
||||
|
||||
### Tmux Plugins
|
||||
|
||||
This plugin is part of the [tmux-plugins](https://github.com/tmux-plugins) organisation. Checkout plugins as [battery](https://github.com/tmux-plugins/tmux-battery), [logging](https://github.com/tmux-plugins/tmux-logging), [online status](https://github.com/tmux-plugins/tmux-online-status), and many more over at the [tmux-plugins](https://github.com/tmux-plugins) organisation page.
|
||||
|
||||
### Maintainers
|
||||
|
||||
- [Camille Tjhoa](https://github.com/ctjhoa)
|
||||
- [Casper da Costa-Luis](https://github.com/casperdcl)
|
||||
|
||||
### License
|
||||
|
||||
[MIT](LICENSE.md)
|
85
tmux/.tmux/plugins/tmux-cpu/cpu.tmux
Executable file
@ -0,0 +1,85 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
source "$CURRENT_DIR/scripts/helpers.sh"
|
||||
|
||||
cpu_interpolation=(
|
||||
"\#{cpu_percentage}"
|
||||
"\#{cpu_icon}"
|
||||
"\#{cpu_bg_color}"
|
||||
"\#{cpu_fg_color}"
|
||||
"\#{gpu_percentage}"
|
||||
"\#{gpu_icon}"
|
||||
"\#{gpu_bg_color}"
|
||||
"\#{gpu_fg_color}"
|
||||
"\#{ram_percentage}"
|
||||
"\#{ram_icon}"
|
||||
"\#{ram_bg_color}"
|
||||
"\#{ram_fg_color}"
|
||||
"\#{gram_percentage}"
|
||||
"\#{gram_icon}"
|
||||
"\#{gram_bg_color}"
|
||||
"\#{gram_fg_color}"
|
||||
"\#{cpu_temp}"
|
||||
"\#{cpu_temp_icon}"
|
||||
"\#{cpu_temp_bg_color}"
|
||||
"\#{cpu_temp_fg_color}"
|
||||
"\#{gpu_temp}"
|
||||
"\#{gpu_temp_icon}"
|
||||
"\#{gpu_temp_bg_color}"
|
||||
"\#{gpu_temp_fg_color}"
|
||||
)
|
||||
cpu_commands=(
|
||||
"#($CURRENT_DIR/scripts/cpu_percentage.sh)"
|
||||
"#($CURRENT_DIR/scripts/cpu_icon.sh)"
|
||||
"#($CURRENT_DIR/scripts/cpu_bg_color.sh)"
|
||||
"#($CURRENT_DIR/scripts/cpu_fg_color.sh)"
|
||||
"#($CURRENT_DIR/scripts/gpu_percentage.sh)"
|
||||
"#($CURRENT_DIR/scripts/gpu_icon.sh)"
|
||||
"#($CURRENT_DIR/scripts/gpu_bg_color.sh)"
|
||||
"#($CURRENT_DIR/scripts/gpu_fg_color.sh)"
|
||||
"#($CURRENT_DIR/scripts/ram_percentage.sh)"
|
||||
"#($CURRENT_DIR/scripts/ram_icon.sh)"
|
||||
"#($CURRENT_DIR/scripts/ram_bg_color.sh)"
|
||||
"#($CURRENT_DIR/scripts/ram_fg_color.sh)"
|
||||
"#($CURRENT_DIR/scripts/gram_percentage.sh)"
|
||||
"#($CURRENT_DIR/scripts/gram_icon.sh)"
|
||||
"#($CURRENT_DIR/scripts/gram_bg_color.sh)"
|
||||
"#($CURRENT_DIR/scripts/gram_fg_color.sh)"
|
||||
"#($CURRENT_DIR/scripts/cpu_temp.sh)"
|
||||
"#($CURRENT_DIR/scripts/cpu_temp_icon.sh)"
|
||||
"#($CURRENT_DIR/scripts/cpu_temp_bg_color.sh)"
|
||||
"#($CURRENT_DIR/scripts/cpu_temp_fg_color.sh)"
|
||||
"#($CURRENT_DIR/scripts/gpu_temp.sh)"
|
||||
"#($CURRENT_DIR/scripts/gpu_temp_icon.sh)"
|
||||
"#($CURRENT_DIR/scripts/gpu_temp_bg_color.sh)"
|
||||
"#($CURRENT_DIR/scripts/gpu_temp_fg_color.sh)"
|
||||
)
|
||||
|
||||
set_tmux_option() {
|
||||
local option=$1
|
||||
local value=$2
|
||||
tmux set-option -gq "$option" "$value"
|
||||
}
|
||||
|
||||
do_interpolation() {
|
||||
local all_interpolated="$1"
|
||||
for ((i=0; i<${#cpu_commands[@]}; i++)); do
|
||||
all_interpolated=${all_interpolated//${cpu_interpolation[$i]}/${cpu_commands[$i]}}
|
||||
done
|
||||
echo "$all_interpolated"
|
||||
}
|
||||
|
||||
update_tmux_option() {
|
||||
local option=$1
|
||||
local option_value=$(get_tmux_option "$option")
|
||||
local new_option_value=$(do_interpolation "$option_value")
|
||||
set_tmux_option "$option" "$new_option_value"
|
||||
}
|
||||
|
||||
main() {
|
||||
update_tmux_option "status-right"
|
||||
update_tmux_option "status-left"
|
||||
}
|
||||
main
|
BIN
tmux/.tmux/plugins/tmux-cpu/screenshots/high_bg.png
Normal file
After Width: | Height: | Size: 992 B |
BIN
tmux/.tmux/plugins/tmux-cpu/screenshots/high_fg.png
Normal file
After Width: | Height: | Size: 919 B |
BIN
tmux/.tmux/plugins/tmux-cpu/screenshots/high_icon.png
Normal file
After Width: | Height: | Size: 1.0 KiB |
BIN
tmux/.tmux/plugins/tmux-cpu/screenshots/low_bg.png
Normal file
After Width: | Height: | Size: 908 B |
BIN
tmux/.tmux/plugins/tmux-cpu/screenshots/low_fg.png
Normal file
After Width: | Height: | Size: 855 B |
BIN
tmux/.tmux/plugins/tmux-cpu/screenshots/low_icon.png
Normal file
After Width: | Height: | Size: 1016 B |
BIN
tmux/.tmux/plugins/tmux-cpu/screenshots/medium_bg.png
Normal file
After Width: | Height: | Size: 1.3 KiB |
BIN
tmux/.tmux/plugins/tmux-cpu/screenshots/medium_fg.png
Normal file
After Width: | Height: | Size: 1.1 KiB |
BIN
tmux/.tmux/plugins/tmux-cpu/screenshots/medium_icon.png
Normal file
After Width: | Height: | Size: 1.2 KiB |
37
tmux/.tmux/plugins/tmux-cpu/scripts/cpu_bg_color.sh
Executable file
@ -0,0 +1,37 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
source "$CURRENT_DIR/helpers.sh"
|
||||
|
||||
cpu_low_bg_color=""
|
||||
cpu_medium_bg_color=""
|
||||
cpu_high_bg_color=""
|
||||
|
||||
cpu_low_default_bg_color="#[bg=green]"
|
||||
cpu_medium_default_bg_color="#[bg=yellow]"
|
||||
cpu_high_default_bg_color="#[bg=red]"
|
||||
|
||||
get_bg_color_settings() {
|
||||
cpu_low_bg_color=$(get_tmux_option "@cpu_low_bg_color" "$cpu_low_default_bg_color")
|
||||
cpu_medium_bg_color=$(get_tmux_option "@cpu_medium_bg_color" "$cpu_medium_default_bg_color")
|
||||
cpu_high_bg_color=$(get_tmux_option "@cpu_high_bg_color" "$cpu_high_default_bg_color")
|
||||
}
|
||||
|
||||
print_bg_color() {
|
||||
local cpu_percentage=$($CURRENT_DIR/cpu_percentage.sh | sed -e 's/%//')
|
||||
local load_status=$(load_status $cpu_percentage)
|
||||
if [ $load_status == "low" ]; then
|
||||
echo "$cpu_low_bg_color"
|
||||
elif [ $load_status == "medium" ]; then
|
||||
echo "$cpu_medium_bg_color"
|
||||
elif [ $load_status == "high" ]; then
|
||||
echo "$cpu_high_bg_color"
|
||||
fi
|
||||
}
|
||||
|
||||
main() {
|
||||
get_bg_color_settings
|
||||
print_bg_color
|
||||
}
|
||||
main
|
37
tmux/.tmux/plugins/tmux-cpu/scripts/cpu_fg_color.sh
Executable file
@ -0,0 +1,37 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
source "$CURRENT_DIR/helpers.sh"
|
||||
|
||||
cpu_low_fg_color=""
|
||||
cpu_medium_fg_color=""
|
||||
cpu_high_fg_color=""
|
||||
|
||||
cpu_low_default_fg_color="#[fg=green]"
|
||||
cpu_medium_default_fg_color="#[fg=yellow]"
|
||||
cpu_high_default_fg_color="#[fg=red]"
|
||||
|
||||
get_fg_color_settings() {
|
||||
cpu_low_fg_color=$(get_tmux_option "@cpu_low_fg_color" "$cpu_low_default_fg_color")
|
||||
cpu_medium_fg_color=$(get_tmux_option "@cpu_medium_fg_color" "$cpu_medium_default_fg_color")
|
||||
cpu_high_fg_color=$(get_tmux_option "@cpu_high_fg_color" "$cpu_high_default_fg_color")
|
||||
}
|
||||
|
||||
print_fg_color() {
|
||||
local cpu_percentage=$($CURRENT_DIR/cpu_percentage.sh | sed -e 's/%//')
|
||||
local load_status=$(load_status $cpu_percentage)
|
||||
if [ $load_status == "low" ]; then
|
||||
echo "$cpu_low_fg_color"
|
||||
elif [ $load_status == "medium" ]; then
|
||||
echo "$cpu_medium_fg_color"
|
||||
elif [ $load_status == "high" ]; then
|
||||
echo "$cpu_high_fg_color"
|
||||
fi
|
||||
}
|
||||
|
||||
main() {
|
||||
get_fg_color_settings
|
||||
print_fg_color
|
||||
}
|
||||
main
|
39
tmux/.tmux/plugins/tmux-cpu/scripts/cpu_icon.sh
Executable file
@ -0,0 +1,39 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
source "$CURRENT_DIR/helpers.sh"
|
||||
|
||||
# script global variables
|
||||
cpu_low_icon=""
|
||||
cpu_medium_icon=""
|
||||
cpu_high_icon=""
|
||||
|
||||
cpu_low_default_icon="="
|
||||
cpu_medium_default_icon="≡"
|
||||
cpu_high_default_icon="≣"
|
||||
|
||||
# icons are set as script global variables
|
||||
get_icon_settings() {
|
||||
cpu_low_icon=$(get_tmux_option "@cpu_low_icon" "$cpu_low_default_icon")
|
||||
cpu_medium_icon=$(get_tmux_option "@cpu_medium_icon" "$cpu_medium_default_icon")
|
||||
cpu_high_icon=$(get_tmux_option "@cpu_high_icon" "$cpu_high_default_icon")
|
||||
}
|
||||
|
||||
print_icon() {
|
||||
local cpu_percentage=$($CURRENT_DIR/cpu_percentage.sh | sed -e 's/%//')
|
||||
local load_status=$(load_status $cpu_percentage)
|
||||
if [ $load_status == "low" ]; then
|
||||
echo "$cpu_low_icon"
|
||||
elif [ $load_status == "medium" ]; then
|
||||
echo "$cpu_medium_icon"
|
||||
elif [ $load_status == "high" ]; then
|
||||
echo "$cpu_high_icon"
|
||||
fi
|
||||
}
|
||||
|
||||
main() {
|
||||
get_icon_settings
|
||||
print_icon "$1"
|
||||
}
|
||||
main
|
40
tmux/.tmux/plugins/tmux-cpu/scripts/cpu_percentage.sh
Executable file
@ -0,0 +1,40 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
source "$CURRENT_DIR/helpers.sh"
|
||||
|
||||
cpu_percentage_format="%3.1f%%"
|
||||
|
||||
print_cpu_percentage() {
|
||||
cpu_percentage_format=$(get_tmux_option "@cpu_percentage_format" "$cpu_percentage_format")
|
||||
|
||||
if command_exists "iostat"; then
|
||||
|
||||
if is_linux_iostat; then
|
||||
cached_eval iostat -c 1 2 | sed '/^\s*$/d' | tail -n 1 | awk -v format="$cpu_percentage_format" '{usage=100-$NF} END {printf(format, usage)}' | sed 's/,/./'
|
||||
elif is_osx; then
|
||||
cached_eval iostat -c 2 disk0 | sed '/^\s*$/d' | tail -n 1 | awk -v format="$cpu_percentage_format" '{usage=100-$6} END {printf(format, usage)}' | sed 's/,/./'
|
||||
elif is_freebsd || is_openbsd; then
|
||||
cached_eval iostat -c 2 | sed '/^\s*$/d' | tail -n 1 | awk -v format="$cpu_percentage_format" '{usage=100-$NF} END {printf(format, usage)}' | sed 's/,/./'
|
||||
else
|
||||
echo "Unknown iostat version please create an issue"
|
||||
fi
|
||||
elif command_exists "sar"; then
|
||||
cached_eval sar -u 1 1 | sed '/^\s*$/d' | tail -n 1 | awk -v format="$cpu_percentage_format" '{usage=100-$NF} END {printf(format, usage)}' | sed 's/,/./'
|
||||
else
|
||||
if is_cygwin; then
|
||||
usage="$(cached_eval WMIC cpu get LoadPercentage | grep -Eo '^[0-9]+')"
|
||||
printf "$cpu_percentage_format" "$usage"
|
||||
else
|
||||
load=`cached_eval ps -aux | awk '{print $3}' | tail -n+2 | awk '{s+=$1} END {print s}'`
|
||||
cpus=$(cpus_number)
|
||||
echo "$load $cpus" | awk -v format="$cpu_percentage_format" '{printf format, $1/$2}'
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
main() {
|
||||
print_cpu_percentage
|
||||
}
|
||||
main
|
21
tmux/.tmux/plugins/tmux-cpu/scripts/cpu_temp.sh
Executable file
@ -0,0 +1,21 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
source "$CURRENT_DIR/helpers.sh"
|
||||
|
||||
cpu_temp_format="%2.0f"
|
||||
cpu_temp_unit="C"
|
||||
|
||||
print_cpu_temp() {
|
||||
cpu_temp_format=$(get_tmux_option "@cpu_temp_format" "$cpu_temp_format")
|
||||
cpu_temp_unit=$(get_tmux_option "@cpu_temp_unit" "$cpu_temp_unit")
|
||||
if command_exists "sensors"; then
|
||||
([ "$cpu_temp_unit" == F ] && sensors -f || sensors) | sed -e 's/^Tccd/Core /' | awk -v format="$cpu_temp_format$cpu_temp_unit" '/^Core [0-9]+/ {gsub("[^0-9.]", "", $3); sum+=$3; n+=1} END {printf(format, sum/n)}'
|
||||
fi
|
||||
}
|
||||
|
||||
main() {
|
||||
print_cpu_temp
|
||||
}
|
||||
main
|
37
tmux/.tmux/plugins/tmux-cpu/scripts/cpu_temp_bg_color.sh
Executable file
@ -0,0 +1,37 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
source "$CURRENT_DIR/helpers.sh"
|
||||
|
||||
cpu_temp_low_bg_color=""
|
||||
cpu_temp_medium_bg_color=""
|
||||
cpu_temp_high_bg_color=""
|
||||
|
||||
cpu_temp_low_default_bg_color="#[bg=green]"
|
||||
cpu_temp_medium_default_bg_color="#[bg=yellow]"
|
||||
cpu_temp_high_default_bg_color="#[bg=red]"
|
||||
|
||||
get_bg_color_settings() {
|
||||
cpu_temp_low_bg_color=$(get_tmux_option "@cpu_temp_low_bg_color" "$cpu_temp_low_default_bg_color")
|
||||
cpu_temp_medium_bg_color=$(get_tmux_option "@cpu_temp_medium_bg_color" "$cpu_temp_medium_default_bg_color")
|
||||
cpu_temp_high_bg_color=$(get_tmux_option "@cpu_temp_high_bg_color" "$cpu_temp_high_default_bg_color")
|
||||
}
|
||||
|
||||
print_bg_color() {
|
||||
local cpu_temp=$($CURRENT_DIR/cpu_temp.sh | sed -e 's/[^0-9.]//')
|
||||
local cpu_temp_status=$(temp_status $cpu_temp)
|
||||
if [ $cpu_temp_status == "low" ]; then
|
||||
echo "$cpu_temp_low_bg_color"
|
||||
elif [ $cpu_temp_status == "medium" ]; then
|
||||
echo "$cpu_temp_medium_bg_color"
|
||||
elif [ $cpu_temp_status == "high" ]; then
|
||||
echo "$cpu_temp_high_bg_color"
|
||||
fi
|
||||
}
|
||||
|
||||
main() {
|
||||
get_bg_color_settings
|
||||
print_bg_color
|
||||
}
|
||||
main
|
37
tmux/.tmux/plugins/tmux-cpu/scripts/cpu_temp_fg_color.sh
Executable file
@ -0,0 +1,37 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
source "$CURRENT_DIR/helpers.sh"
|
||||
|
||||
cpu_temp_low_fg_color=""
|
||||
cpu_temp_medium_fg_color=""
|
||||
cpu_temp_high_fg_color=""
|
||||
|
||||
cpu_temp_low_default_fg_color="#[fg=green]"
|
||||
cpu_temp_medium_default_fg_color="#[fg=yellow]"
|
||||
cpu_temp_high_default_fg_color="#[fg=red]"
|
||||
|
||||
get_fg_color_settings() {
|
||||
cpu_temp_low_fg_color=$(get_tmux_option "@cpu_temp_low_fg_color" "$cpu_temp_low_default_fg_color")
|
||||
cpu_temp_medium_fg_color=$(get_tmux_option "@cpu_temp_medium_fg_color" "$cpu_temp_medium_default_fg_color")
|
||||
cpu_temp_high_fg_color=$(get_tmux_option "@cpu_temp_high_fg_color" "$cpu_temp_high_default_fg_color")
|
||||
}
|
||||
|
||||
print_fg_color() {
|
||||
local cpu_temp=$($CURRENT_DIR/cpu_temp.sh | sed -e 's/[^0-9.]//')
|
||||
local cpu_temp_status=$(temp_status $cpu_temp)
|
||||
if [ $cpu_temp_status == "low" ]; then
|
||||
echo "$cpu_temp_low_fg_color"
|
||||
elif [ $cpu_temp_status == "medium" ]; then
|
||||
echo "$cpu_temp_medium_fg_color"
|
||||
elif [ $cpu_temp_status == "high" ]; then
|
||||
echo "$cpu_temp_high_fg_color"
|
||||
fi
|
||||
}
|
||||
|
||||
main() {
|
||||
get_fg_color_settings
|
||||
print_fg_color
|
||||
}
|
||||
main
|
39
tmux/.tmux/plugins/tmux-cpu/scripts/cpu_temp_icon.sh
Executable file
@ -0,0 +1,39 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
source "$CURRENT_DIR/helpers.sh"
|
||||
|
||||
# script global variables
|
||||
cpu_temp_low_icon=""
|
||||
cpu_temp_medium_icon=""
|
||||
cpu_temp_high_icon=""
|
||||
|
||||
cpu_temp_low_default_icon="="
|
||||
cpu_temp_medium_default_icon="≡"
|
||||
cpu_temp_high_default_icon="≣"
|
||||
|
||||
# icons are set as script global variables
|
||||
get_icon_settings() {
|
||||
cpu_temp_low_icon=$(get_tmux_option "@cpu_temp_low_icon" "$cpu_temp_low_default_icon")
|
||||
cpu_temp_medium_icon=$(get_tmux_option "@cpu_temp_medium_icon" "$cpu_temp_medium_default_icon")
|
||||
cpu_temp_high_icon=$(get_tmux_option "@cpu_temp_high_icon" "$cpu_temp_high_default_icon")
|
||||
}
|
||||
|
||||
print_icon() {
|
||||
local cpu_temp=$($CURRENT_DIR/cpu_temp.sh | sed -e 's/[^0-9.]//')
|
||||
local cpu_temp_status=$(temp_status $cpu_temp)
|
||||
if [ $cpu_temp_status == "low" ]; then
|
||||
echo "$cpu_temp_low_icon"
|
||||
elif [ $cpu_temp_status == "medium" ]; then
|
||||
echo "$cpu_temp_medium_icon"
|
||||
elif [ $cpu_temp_status == "high" ]; then
|
||||
echo "$cpu_temp_high_icon"
|
||||
fi
|
||||
}
|
||||
|
||||
main() {
|
||||
get_icon_settings
|
||||
print_icon "$1"
|
||||
}
|
||||
main
|
37
tmux/.tmux/plugins/tmux-cpu/scripts/gpu_bg_color.sh
Executable file
@ -0,0 +1,37 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
source "$CURRENT_DIR/helpers.sh"
|
||||
|
||||
gpu_low_bg_color=""
|
||||
gpu_medium_bg_color=""
|
||||
gpu_high_bg_color=""
|
||||
|
||||
gpu_low_default_bg_color="#[bg=green]"
|
||||
gpu_medium_default_bg_color="#[bg=yellow]"
|
||||
gpu_high_default_bg_color="#[bg=red]"
|
||||
|
||||
get_bg_color_settings() {
|
||||
gpu_low_bg_color=$(get_tmux_option "@gpu_low_bg_color" "$gpu_low_default_bg_color")
|
||||
gpu_medium_bg_color=$(get_tmux_option "@gpu_medium_bg_color" "$gpu_medium_default_bg_color")
|
||||
gpu_high_bg_color=$(get_tmux_option "@gpu_high_bg_color" "$gpu_high_default_bg_color")
|
||||
}
|
||||
|
||||
print_bg_color() {
|
||||
local gpu_percentage=$($CURRENT_DIR/gpu_percentage.sh | sed -e 's/%//')
|
||||
local gpu_load_status=$(load_status $gpu_percentage)
|
||||
if [ $gpu_load_status == "low" ]; then
|
||||
echo "$gpu_low_bg_color"
|
||||
elif [ $gpu_load_status == "medium" ]; then
|
||||
echo "$gpu_medium_bg_color"
|
||||
elif [ $gpu_load_status == "high" ]; then
|
||||
echo "$gpu_high_bg_color"
|
||||
fi
|
||||
}
|
||||
|
||||
main() {
|
||||
get_bg_color_settings
|
||||
print_bg_color
|
||||
}
|
||||
main
|
37
tmux/.tmux/plugins/tmux-cpu/scripts/gpu_fg_color.sh
Executable file
@ -0,0 +1,37 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
source "$CURRENT_DIR/helpers.sh"
|
||||
|
||||
gpu_low_fg_color=""
|
||||
gpu_medium_fg_color=""
|
||||
gpu_high_fg_color=""
|
||||
|
||||
gpu_low_default_fg_color="#[fg=green]"
|
||||
gpu_medium_default_fg_color="#[fg=yellow]"
|
||||
gpu_high_default_fg_color="#[fg=red]"
|
||||
|
||||
get_fg_color_settings() {
|
||||
gpu_low_fg_color=$(get_tmux_option "@gpu_low_fg_color" "$gpu_low_default_fg_color")
|
||||
gpu_medium_fg_color=$(get_tmux_option "@gpu_medium_fg_color" "$gpu_medium_default_fg_color")
|
||||
gpu_high_fg_color=$(get_tmux_option "@gpu_high_fg_color" "$gpu_high_default_fg_color")
|
||||
}
|
||||
|
||||
print_fg_color() {
|
||||
local gpu_percentage=$($CURRENT_DIR/gpu_percentage.sh | sed -e 's/%//')
|
||||
local gpu_load_status=$(load_status $gpu_percentage)
|
||||
if [ $gpu_load_status == "low" ]; then
|
||||
echo "$gpu_low_fg_color"
|
||||
elif [ $gpu_load_status == "medium" ]; then
|
||||
echo "$gpu_medium_fg_color"
|
||||
elif [ $gpu_load_status == "high" ]; then
|
||||
echo "$gpu_high_fg_color"
|
||||
fi
|
||||
}
|
||||
|
||||
main() {
|
||||
get_fg_color_settings
|
||||
print_fg_color
|
||||
}
|
||||
main
|
39
tmux/.tmux/plugins/tmux-cpu/scripts/gpu_icon.sh
Executable file
@ -0,0 +1,39 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
source "$CURRENT_DIR/helpers.sh"
|
||||
|
||||
# script global variables
|
||||
gpu_low_icon=""
|
||||
gpu_medium_icon=""
|
||||
gpu_high_icon=""
|
||||
|
||||
gpu_low_default_icon="="
|
||||
gpu_medium_default_icon="≡"
|
||||
gpu_high_default_icon="≣"
|
||||
|
||||
# icons are set as script global variables
|
||||
get_icon_settings() {
|
||||
gpu_low_icon=$(get_tmux_option "@gpu_low_icon" "$gpu_low_default_icon")
|
||||
gpu_medium_icon=$(get_tmux_option "@gpu_medium_icon" "$gpu_medium_default_icon")
|
||||
gpu_high_icon=$(get_tmux_option "@gpu_high_icon" "$gpu_high_default_icon")
|
||||
}
|
||||
|
||||
print_icon() {
|
||||
local gpu_percentage=$($CURRENT_DIR/gpu_percentage.sh | sed -e 's/%//')
|
||||
local gpu_load_status=$(load_status $gpu_percentage)
|
||||
if [ $gpu_load_status == "low" ]; then
|
||||
echo "$gpu_low_icon"
|
||||
elif [ $gpu_load_status == "medium" ]; then
|
||||
echo "$gpu_medium_icon"
|
||||
elif [ $gpu_load_status == "high" ]; then
|
||||
echo "$gpu_high_icon"
|
||||
fi
|
||||
}
|
||||
|
||||
main() {
|
||||
get_icon_settings
|
||||
print_icon "$1"
|
||||
}
|
||||
main
|
26
tmux/.tmux/plugins/tmux-cpu/scripts/gpu_percentage.sh
Executable file
@ -0,0 +1,26 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
source "$CURRENT_DIR/helpers.sh"
|
||||
|
||||
gpu_percentage_format="%3.1f%%"
|
||||
|
||||
print_gpu_percentage() {
|
||||
gpu_percentage_format=$(get_tmux_option "@gpu_percentage_format" "$gpu_percentage_format")
|
||||
|
||||
if command_exists "nvidia-smi"; then
|
||||
loads=$(cached_eval nvidia-smi)
|
||||
elif command_exists "cuda-smi"; then
|
||||
loads=$(cached_eval cuda-smi)
|
||||
else
|
||||
echo "No GPU"
|
||||
return
|
||||
fi
|
||||
echo "$loads" | sed -nr 's/.*\s([0-9]+)%.*/\1/p' | awk -v format="$gpu_percentage_format" '{sum+=$1; n+=1} END {printf format, sum/n}'
|
||||
}
|
||||
|
||||
main() {
|
||||
print_gpu_percentage
|
||||
}
|
||||
main
|
33
tmux/.tmux/plugins/tmux-cpu/scripts/gpu_temp.sh
Executable file
@ -0,0 +1,33 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
source "$CURRENT_DIR/helpers.sh"
|
||||
|
||||
gpu_temp_format="%2.0f"
|
||||
gpu_temp_unit="C"
|
||||
|
||||
print_gpu_temp() {
|
||||
gpu_temp_format=$(get_tmux_option "@gpu_temp_format" "$gpu_temp_format")
|
||||
gpu_temp_unit=$(get_tmux_option "@gpu_temp_unit" "$gpu_temp_unit")
|
||||
|
||||
if command_exists "nvidia-smi"; then
|
||||
loads=$(cached_eval nvidia-smi)
|
||||
elif command_exists "cuda-smi"; then
|
||||
loads=$(cached_eval cuda-smi)
|
||||
else
|
||||
echo "No GPU"
|
||||
return
|
||||
fi
|
||||
tempC=$(echo "$loads" | sed -nr 's/.*\s([0-9]+)C.*/\1/p' | awk '{sum+=$1; n+=1} END {printf "%5.3f", sum/n}')
|
||||
if [ $gpu_temp_unit == "C" ]; then
|
||||
echo "$tempC" | awk -v format="${gpu_temp_format}C" '{sum+=$1} END {printf format, sum}'
|
||||
else
|
||||
echo "$tempC" | awk -v format="${gpu_temp_format}F" '{sum+=$1} END {printf format, sum*9/5+32}'
|
||||
fi
|
||||
}
|
||||
|
||||
main() {
|
||||
print_gpu_temp
|
||||
}
|
||||
main
|
37
tmux/.tmux/plugins/tmux-cpu/scripts/gpu_temp_bg_color.sh
Executable file
@ -0,0 +1,37 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
source "$CURRENT_DIR/helpers.sh"
|
||||
|
||||
gpu_temp_low_bg_color=""
|
||||
gpu_temp_medium_bg_color=""
|
||||
gpu_temp_high_bg_color=""
|
||||
|
||||
gpu_temp_low_default_bg_color="#[bg=green]"
|
||||
gpu_temp_medium_default_bg_color="#[bg=yellow]"
|
||||
gpu_temp_high_default_bg_color="#[bg=red]"
|
||||
|
||||
get_bg_color_settings() {
|
||||
gpu_temp_low_bg_color=$(get_tmux_option "@gpu_temp_low_bg_color" "$gpu_temp_low_default_bg_color")
|
||||
gpu_temp_medium_bg_color=$(get_tmux_option "@gpu_temp_medium_bg_color" "$gpu_temp_medium_default_bg_color")
|
||||
gpu_temp_high_bg_color=$(get_tmux_option "@gpu_temp_high_bg_color" "$gpu_temp_high_default_bg_color")
|
||||
}
|
||||
|
||||
print_bg_color() {
|
||||
local gpu_temp=$($CURRENT_DIR/gpu_temp.sh | sed -e 's/[^0-9.]//')
|
||||
local gpu_temp_status=$(temp_status $gpu_temp)
|
||||
if [ $gpu_temp_status == "low" ]; then
|
||||
echo "$gpu_temp_low_bg_color"
|
||||
elif [ $gpu_temp_status == "medium" ]; then
|
||||
echo "$gpu_temp_medium_bg_color"
|
||||
elif [ $gpu_temp_status == "high" ]; then
|
||||
echo "$gpu_temp_high_bg_color"
|
||||
fi
|
||||
}
|
||||
|
||||
main() {
|
||||
get_bg_color_settings
|
||||
print_bg_color
|
||||
}
|
||||
main
|
37
tmux/.tmux/plugins/tmux-cpu/scripts/gpu_temp_fg_color.sh
Executable file
@ -0,0 +1,37 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
source "$CURRENT_DIR/helpers.sh"
|
||||
|
||||
gpu_temp_low_fg_color=""
|
||||
gpu_temp_medium_fg_color=""
|
||||
gpu_temp_high_fg_color=""
|
||||
|
||||
gpu_temp_low_default_fg_color="#[fg=green]"
|
||||
gpu_temp_medium_default_fg_color="#[fg=yellow]"
|
||||
gpu_temp_high_default_fg_color="#[fg=red]"
|
||||
|
||||
get_fg_color_settings() {
|
||||
gpu_temp_low_fg_color=$(get_tmux_option "@gpu_temp_low_fg_color" "$gpu_temp_low_default_fg_color")
|
||||
gpu_temp_medium_fg_color=$(get_tmux_option "@gpu_temp_medium_fg_color" "$gpu_temp_medium_default_fg_color")
|
||||
gpu_temp_high_fg_color=$(get_tmux_option "@gpu_temp_high_fg_color" "$gpu_temp_high_default_fg_color")
|
||||
}
|
||||
|
||||
print_fg_color() {
|
||||
local gpu_temp=$($CURRENT_DIR/gpu_temp.sh | sed -e 's/[^0-9.]//')
|
||||
local gpu_temp_status=$(temp_status $gpu_temp)
|
||||
if [ $gpu_temp_status == "low" ]; then
|
||||
echo "$gpu_temp_low_fg_color"
|
||||
elif [ $gpu_temp_status == "medium" ]; then
|
||||
echo "$gpu_temp_medium_fg_color"
|
||||
elif [ $gpu_temp_status == "high" ]; then
|
||||
echo "$gpu_temp_high_fg_color"
|
||||
fi
|
||||
}
|
||||
|
||||
main() {
|
||||
get_fg_color_settings
|
||||
print_fg_color
|
||||
}
|
||||
main
|
39
tmux/.tmux/plugins/tmux-cpu/scripts/gpu_temp_icon.sh
Executable file
@ -0,0 +1,39 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
source "$CURRENT_DIR/helpers.sh"
|
||||
|
||||
# script global variables
|
||||
gpu_temp_low_icon=""
|
||||
gpu_temp_medium_icon=""
|
||||
gpu_temp_high_icon=""
|
||||
|
||||
gpu_temp_low_default_icon="="
|
||||
gpu_temp_medium_default_icon="≡"
|
||||
gpu_temp_high_default_icon="≣"
|
||||
|
||||
# icons are set as script global variables
|
||||
get_icon_settings() {
|
||||
gpu_temp_low_icon=$(get_tmux_option "@gpu_temp_low_icon" "$gpu_temp_low_default_icon")
|
||||
gpu_temp_medium_icon=$(get_tmux_option "@gpu_temp_medium_icon" "$gpu_temp_medium_default_icon")
|
||||
gpu_temp_high_icon=$(get_tmux_option "@gpu_temp_high_icon" "$gpu_temp_high_default_icon")
|
||||
}
|
||||
|
||||
print_icon() {
|
||||
local gpu_temp=$($CURRENT_DIR/gpu_temp.sh | sed -e 's/[^0-9.]//')
|
||||
local gpu_temp_status=$(temp_status $gpu_temp)
|
||||
if [ $gpu_temp_status == "low" ]; then
|
||||
echo "$gpu_temp_low_icon"
|
||||
elif [ $gpu_temp_status == "medium" ]; then
|
||||
echo "$gpu_temp_medium_icon"
|
||||
elif [ $gpu_temp_status == "high" ]; then
|
||||
echo "$gpu_temp_high_icon"
|
||||
fi
|
||||
}
|
||||
|
||||
main() {
|
||||
get_icon_settings
|
||||
print_icon "$1"
|
||||
}
|
||||
main
|
37
tmux/.tmux/plugins/tmux-cpu/scripts/gram_bg_color.sh
Executable file
@ -0,0 +1,37 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
source "$CURRENT_DIR/helpers.sh"
|
||||
|
||||
gram_low_bg_color=""
|
||||
gram_medium_bg_color=""
|
||||
gram_high_bg_color=""
|
||||
|
||||
gram_low_default_bg_color="#[bg=green]"
|
||||
gram_medium_default_bg_color="#[bg=yellow]"
|
||||
gram_high_default_bg_color="#[bg=red]"
|
||||
|
||||
get_bg_color_settings() {
|
||||
gram_low_bg_color=$(get_tmux_option "@gram_low_bg_color" "$gram_low_default_bg_color")
|
||||
gram_medium_bg_color=$(get_tmux_option "@gram_medium_bg_color" "$gram_medium_default_bg_color")
|
||||
gram_high_bg_color=$(get_tmux_option "@gram_high_bg_color" "$gram_high_default_bg_color")
|
||||
}
|
||||
|
||||
print_bg_color() {
|
||||
local gram_percentage=$($CURRENT_DIR/gram_percentage.sh | sed -e 's/%//')
|
||||
local gram_load_status=$(load_status $gram_percentage)
|
||||
if [ $gram_load_status == "low" ]; then
|
||||
echo "$gram_low_bg_color"
|
||||
elif [ $gram_load_status == "medium" ]; then
|
||||
echo "$gram_medium_bg_color"
|
||||
elif [ $gram_load_status == "high" ]; then
|
||||
echo "$gram_high_bg_color"
|
||||
fi
|
||||
}
|
||||
|
||||
main() {
|
||||
get_bg_color_settings
|
||||
print_bg_color
|
||||
}
|
||||
main
|
37
tmux/.tmux/plugins/tmux-cpu/scripts/gram_fg_color.sh
Executable file
@ -0,0 +1,37 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
source "$CURRENT_DIR/helpers.sh"
|
||||
|
||||
gram_low_fg_color=""
|
||||
gram_medium_fg_color=""
|
||||
gram_high_fg_color=""
|
||||
|
||||
gram_low_default_fg_color="#[fg=green]"
|
||||
gram_medium_default_fg_color="#[fg=yellow]"
|
||||
gram_high_default_fg_color="#[fg=red]"
|
||||
|
||||
get_fg_color_settings() {
|
||||
gram_low_fg_color=$(get_tmux_option "@gram_low_fg_color" "$gram_low_default_fg_color")
|
||||
gram_medium_fg_color=$(get_tmux_option "@gram_medium_fg_color" "$gram_medium_default_fg_color")
|
||||
gram_high_fg_color=$(get_tmux_option "@gram_high_fg_color" "$gram_high_default_fg_color")
|
||||
}
|
||||
|
||||
print_fg_color() {
|
||||
local gram_percentage=$($CURRENT_DIR/gram_percentage.sh | sed -e 's/%//')
|
||||
local gram_load_status=$(load_status $gram_percentage)
|
||||
if [ $gram_load_status == "low" ]; then
|
||||
echo "$gram_low_fg_color"
|
||||
elif [ $gram_load_status == "medium" ]; then
|
||||
echo "$gram_medium_fg_color"
|
||||
elif [ $gram_load_status == "high" ]; then
|
||||
echo "$gram_high_fg_color"
|
||||
fi
|
||||
}
|
||||
|
||||
main() {
|
||||
get_fg_color_settings
|
||||
print_fg_color
|
||||
}
|
||||
main
|
39
tmux/.tmux/plugins/tmux-cpu/scripts/gram_icon.sh
Executable file
@ -0,0 +1,39 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
source "$CURRENT_DIR/helpers.sh"
|
||||
|
||||
# script global variables
|
||||
gram_low_icon=""
|
||||
gram_medium_icon=""
|
||||
gram_high_icon=""
|
||||
|
||||
gram_low_default_icon="="
|
||||
gram_medium_default_icon="≡"
|
||||
gram_high_default_icon="≣"
|
||||
|
||||
# icons are set as script global variables
|
||||
get_icon_settings() {
|
||||
gram_low_icon=$(get_tmux_option "@gram_low_icon" "$gram_low_default_icon")
|
||||
gram_medium_icon=$(get_tmux_option "@gram_medium_icon" "$gram_medium_default_icon")
|
||||
gram_high_icon=$(get_tmux_option "@gram_high_icon" "$gram_high_default_icon")
|
||||
}
|
||||
|
||||
print_icon() {
|
||||
local gram_percentage=$($CURRENT_DIR/gram_percentage.sh | sed -e 's/%//')
|
||||
local gram_load_status=$(load_status $gram_percentage)
|
||||
if [ $gram_load_status == "low" ]; then
|
||||
echo "$gram_low_icon"
|
||||
elif [ $gram_load_status == "medium" ]; then
|
||||
echo "$gram_medium_icon"
|
||||
elif [ $gram_load_status == "high" ]; then
|
||||
echo "$gram_high_icon"
|
||||
fi
|
||||
}
|
||||
|
||||
main() {
|
||||
get_icon_settings
|
||||
print_icon "$1"
|
||||
}
|
||||
main
|
26
tmux/.tmux/plugins/tmux-cpu/scripts/gram_percentage.sh
Executable file
@ -0,0 +1,26 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
source "$CURRENT_DIR/helpers.sh"
|
||||
|
||||
gram_percentage_format="%3.1f%%"
|
||||
|
||||
print_gram_percentage() {
|
||||
gram_percentage_format=$(get_tmux_option "@gram_percentage_format" "$gram_percentage_format")
|
||||
|
||||
if command_exists "nvidia-smi"; then
|
||||
loads=$(cached_eval nvidia-smi | sed -nr 's/.*\s([0-9]+)MiB\s*\/\s*([0-9]+)MiB.*/\1 \2/p')
|
||||
elif command_exists "cuda-smi"; then
|
||||
loads=$(cached_eval cuda-smi | sed -nr 's/.*\s([0-9.]+) of ([0-9.]+) MB.*/\1 \2/p' | awk '{print $2-$1" "$2}')
|
||||
else
|
||||
echo "No GPU"
|
||||
return
|
||||
fi
|
||||
echo "$loads" | awk -v format="$gram_percentage_format" '{used+=$1; tot+=$2} END {printf format, 100*$1/$2}'
|
||||
}
|
||||
|
||||
main() {
|
||||
print_gram_percentage
|
||||
}
|
||||
main
|
132
tmux/.tmux/plugins/tmux-cpu/scripts/helpers.sh
Normal file
@ -0,0 +1,132 @@
|
||||
export LANG=C
|
||||
export LC_ALL=C
|
||||
|
||||
get_tmux_option() {
|
||||
local option="$1"
|
||||
local default_value="$2"
|
||||
local option_value="$(tmux show-option -qv "$option")"
|
||||
if [ -z "$option_value" ]; then
|
||||
option_value="$(tmux show-option -gqv "$option")"
|
||||
fi
|
||||
if [ -z "$option_value" ]; then
|
||||
echo "$default_value"
|
||||
else
|
||||
echo "$option_value"
|
||||
fi
|
||||
}
|
||||
|
||||
is_osx() {
|
||||
[ $(uname) == "Darwin" ]
|
||||
}
|
||||
|
||||
is_freebsd() {
|
||||
[ $(uname) == "FreeBSD" ]
|
||||
}
|
||||
|
||||
is_openbsd() {
|
||||
[ $(uname) == "OpenBSD" ]
|
||||
}
|
||||
|
||||
is_linux() {
|
||||
[ $(uname) == "Linux" ]
|
||||
}
|
||||
|
||||
is_cygwin() {
|
||||
command -v WMIC &> /dev/null
|
||||
}
|
||||
|
||||
is_linux_iostat() {
|
||||
# Bug in early versions of linux iostat -V return error code
|
||||
iostat -c &> /dev/null
|
||||
}
|
||||
|
||||
# is second float bigger or equal?
|
||||
fcomp() {
|
||||
awk -v n1=$1 -v n2=$2 'BEGIN {if (n1<=n2) exit 0; exit 1}'
|
||||
}
|
||||
|
||||
load_status() {
|
||||
local percentage=$1
|
||||
cpu_medium_thresh=$(get_tmux_option "@cpu_medium_thresh" "30")
|
||||
cpu_high_thresh=$(get_tmux_option "@cpu_high_thresh" "80")
|
||||
if fcomp $cpu_high_thresh $percentage; then
|
||||
echo "high"
|
||||
elif fcomp $cpu_medium_thresh $percentage && fcomp $percentage $cpu_high_thresh; then
|
||||
echo "medium"
|
||||
else
|
||||
echo "low"
|
||||
fi
|
||||
}
|
||||
|
||||
temp_status() {
|
||||
local temp=$1
|
||||
cpu_temp_medium_thresh=$(get_tmux_option "@cpu_temp_medium_thresh" "80")
|
||||
cpu_temp_high_thresh=$(get_tmux_option "@cpu_temp_high_thresh" "90")
|
||||
if fcomp $cpu_temp_high_thresh $temp; then
|
||||
echo "high"
|
||||
elif fcomp $cpu_temp_medium_thresh $temp && fcomp $temp $cpu_temp_high_thresh; then
|
||||
echo "medium"
|
||||
else
|
||||
echo "low"
|
||||
fi
|
||||
}
|
||||
|
||||
cpus_number() {
|
||||
if is_linux; then
|
||||
if command_exists "nproc"; then
|
||||
nproc
|
||||
else
|
||||
echo "$(( $(sed -n 's/^processor.*:\s*\([0-9]\+\)/\1/p' /proc/cpuinfo | tail -n 1) + 1 ))"
|
||||
fi
|
||||
else
|
||||
sysctl -n hw.ncpu
|
||||
fi
|
||||
}
|
||||
|
||||
command_exists() {
|
||||
local command="$1"
|
||||
command -v "$command" &> /dev/null
|
||||
}
|
||||
|
||||
get_tmp_dir() {
|
||||
local tmpdir="${TMPDIR:-${TMP:-${TEMP:-/tmp}}}"
|
||||
[ -d "$tmpdir" ] || local tmpdir=~/tmp
|
||||
echo "$tmpdir/tmux-$EUID-cpu"
|
||||
}
|
||||
|
||||
get_time() {
|
||||
date +%s.%N
|
||||
}
|
||||
|
||||
get_cache_val(){
|
||||
local key="$1"
|
||||
# seconds after which cache is invalidated
|
||||
local timeout="${2:-2}"
|
||||
local cache="$(get_tmp_dir)/$key"
|
||||
if [ -f "$cache" ]; then
|
||||
awk -v cache="$(head -n1 "$cache")" -v timeout=$timeout -v now=$(get_time) \
|
||||
'BEGIN {if (now - timeout < cache) exit 0; exit 1}' \
|
||||
&& tail -n+2 "$cache"
|
||||
fi
|
||||
}
|
||||
|
||||
put_cache_val(){
|
||||
local key="$1"
|
||||
local val="${@:2}"
|
||||
local tmpdir="$(get_tmp_dir)"
|
||||
[ ! -d "$tmpdir" ] && mkdir -p "$tmpdir" && chmod 0700 "$tmpdir"
|
||||
echo "$(get_time)" > "$tmpdir/$key"
|
||||
echo -n "$val" >> "$tmpdir/$key"
|
||||
echo -n "$val"
|
||||
}
|
||||
|
||||
cached_eval(){
|
||||
local command="$1"
|
||||
local key="$(basename "$command")"
|
||||
local val="$(get_cache_val "$key")"
|
||||
if [ -z "$val" ]; then
|
||||
put_cache_val "$key" "$($command "${@:2}")"
|
||||
else
|
||||
echo -n "$val"
|
||||
fi
|
||||
}
|
37
tmux/.tmux/plugins/tmux-cpu/scripts/ram_bg_color.sh
Executable file
@ -0,0 +1,37 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
source "$CURRENT_DIR/helpers.sh"
|
||||
|
||||
ram_low_bg_color=""
|
||||
ram_medium_bg_color=""
|
||||
ram_high_bg_color=""
|
||||
|
||||
ram_low_default_bg_color="#[bg=green]"
|
||||
ram_medium_default_bg_color="#[bg=yellow]"
|
||||
ram_high_default_bg_color="#[bg=red]"
|
||||
|
||||
get_bg_color_settings() {
|
||||
ram_low_bg_color=$(get_tmux_option "@ram_low_bg_color" "$ram_low_default_bg_color")
|
||||
ram_medium_bg_color=$(get_tmux_option "@ram_medium_bg_color" "$ram_medium_default_bg_color")
|
||||
ram_high_bg_color=$(get_tmux_option "@ram_high_bg_color" "$ram_high_default_bg_color")
|
||||
}
|
||||
|
||||
print_bg_color() {
|
||||
local ram_percentage=$($CURRENT_DIR/ram_percentage.sh | sed -e 's/%//')
|
||||
local ram_load_status=$(load_status $ram_percentage)
|
||||
if [ $ram_load_status == "low" ]; then
|
||||
echo "$ram_low_bg_color"
|
||||
elif [ $ram_load_status == "medium" ]; then
|
||||
echo "$ram_medium_bg_color"
|
||||
elif [ $ram_load_status == "high" ]; then
|
||||
echo "$ram_high_bg_color"
|
||||
fi
|
||||
}
|
||||
|
||||
main() {
|
||||
get_bg_color_settings
|
||||
print_bg_color
|
||||
}
|
||||
main
|
37
tmux/.tmux/plugins/tmux-cpu/scripts/ram_fg_color.sh
Executable file
@ -0,0 +1,37 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
source "$CURRENT_DIR/helpers.sh"
|
||||
|
||||
ram_low_fg_color=""
|
||||
ram_medium_fg_color=""
|
||||
ram_high_fg_color=""
|
||||
|
||||
ram_low_default_fg_color="#[fg=green]"
|
||||
ram_medium_default_fg_color="#[fg=yellow]"
|
||||
ram_high_default_fg_color="#[fg=red]"
|
||||
|
||||
get_fg_color_settings() {
|
||||
ram_low_fg_color=$(get_tmux_option "@ram_low_fg_color" "$ram_low_default_fg_color")
|
||||
ram_medium_fg_color=$(get_tmux_option "@ram_medium_fg_color" "$ram_medium_default_fg_color")
|
||||
ram_high_fg_color=$(get_tmux_option "@ram_high_fg_color" "$ram_high_default_fg_color")
|
||||
}
|
||||
|
||||
print_fg_color() {
|
||||
local ram_percentage=$($CURRENT_DIR/ram_percentage.sh | sed -e 's/%//')
|
||||
local ram_load_status=$(load_status $ram_percentage)
|
||||
if [ $ram_load_status == "low" ]; then
|
||||
echo "$ram_low_fg_color"
|
||||
elif [ $ram_load_status == "medium" ]; then
|
||||
echo "$ram_medium_fg_color"
|
||||
elif [ $ram_load_status == "high" ]; then
|
||||
echo "$ram_high_fg_color"
|
||||
fi
|
||||
}
|
||||
|
||||
main() {
|
||||
get_fg_color_settings
|
||||
print_fg_color
|
||||
}
|
||||
main
|
39
tmux/.tmux/plugins/tmux-cpu/scripts/ram_icon.sh
Executable file
@ -0,0 +1,39 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
source "$CURRENT_DIR/helpers.sh"
|
||||
|
||||
# script global variables
|
||||
ram_low_icon=""
|
||||
ram_medium_icon=""
|
||||
ram_high_icon=""
|
||||
|
||||
ram_low_default_icon="="
|
||||
ram_medium_default_icon="≡"
|
||||
ram_high_default_icon="≣"
|
||||
|
||||
# icons are set as script global variables
|
||||
get_icon_settings() {
|
||||
ram_low_icon=$(get_tmux_option "@ram_low_icon" "$ram_low_default_icon")
|
||||
ram_medium_icon=$(get_tmux_option "@ram_medium_icon" "$ram_medium_default_icon")
|
||||
ram_high_icon=$(get_tmux_option "@ram_high_icon" "$ram_high_default_icon")
|
||||
}
|
||||
|
||||
print_icon() {
|
||||
local ram_percentage=$($CURRENT_DIR/ram_percentage.sh | sed -e 's/%//')
|
||||
local ram_load_status=$(load_status $ram_percentage)
|
||||
if [ $ram_load_status == "low" ]; then
|
||||
echo "$ram_low_icon"
|
||||
elif [ $ram_load_status == "medium" ]; then
|
||||
echo "$ram_medium_icon"
|
||||
elif [ $ram_load_status == "high" ]; then
|
||||
echo "$ram_high_icon"
|
||||
fi
|
||||
}
|
||||
|
||||
main() {
|
||||
get_icon_settings
|
||||
print_icon "$1"
|
||||
}
|
||||
main
|
48
tmux/.tmux/plugins/tmux-cpu/scripts/ram_percentage.sh
Executable file
@ -0,0 +1,48 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
source "$CURRENT_DIR/helpers.sh"
|
||||
|
||||
ram_percentage_format="%3.1f%%"
|
||||
|
||||
sum_macos_vm_stats() {
|
||||
grep -Eo '[0-9]+' \
|
||||
| awk '{ a += $1 * 4096 } END { print a }'
|
||||
}
|
||||
|
||||
print_ram_percentage() {
|
||||
ram_percentage_format=$(get_tmux_option "@ram_percentage_format" "$ram_percentage_format")
|
||||
|
||||
if command_exists "free"; then
|
||||
cached_eval free | awk -v format="$ram_percentage_format" '$1 ~ /Mem/ {printf(format, 100*$3/$2)}'
|
||||
elif command_exists "vm_stat"; then
|
||||
# page size of 4096 bytes
|
||||
stats="$(cached_eval vm_stat)"
|
||||
|
||||
used_and_cached=$(echo "$stats" \
|
||||
| grep -E "(Pages active|Pages inactive|Pages speculative|Pages wired down|Pages occupied by compressor)" \
|
||||
| sum_macos_vm_stats \
|
||||
)
|
||||
|
||||
cached=$(echo "$stats" \
|
||||
| grep -E "(Pages purgeable|File-backed pages)" \
|
||||
| sum_macos_vm_stats \
|
||||
)
|
||||
|
||||
free=$(echo "$stats" \
|
||||
| grep -E "(Pages free)" \
|
||||
| sum_macos_vm_stats \
|
||||
)
|
||||
|
||||
used=$(($used_and_cached - $cached))
|
||||
total=$(($used_and_cached + $free))
|
||||
|
||||
echo "$used $total" | awk -v format="$ram_percentage_format" '{printf(format, 100*$1/$2)}'
|
||||
fi
|
||||
}
|
||||
|
||||
main() {
|
||||
print_ram_percentage
|
||||
}
|
||||
main
|
2
tmux/.tmux/plugins/tmux-sensible/.gitattributes
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
# Force text files to have unix eols, so Windows/Cygwin does not break them
|
||||
*.* eol=lf
|
43
tmux/.tmux/plugins/tmux-sensible/CHANGELOG.md
Normal file
@ -0,0 +1,43 @@
|
||||
# Changelog
|
||||
|
||||
### master
|
||||
- remove `detach-on-destroy`
|
||||
- do not set `aggressive-resize` on iTerm terminal
|
||||
- disable `detach-on-destroy`
|
||||
|
||||
### v3.0.0, 2015-06-24
|
||||
- remove 'almost sensible' feature
|
||||
|
||||
### v2.3.0, 2015-06-24
|
||||
- update to support \*THE\* latest tmux version
|
||||
- bugfix for `prefix + R` key binding
|
||||
- fix for tmux 2.0 `default-terminal` option (thanks @kwbr)
|
||||
|
||||
### v2.2.0, 2015-02-10
|
||||
- bugfix in `key_binding_not_set`: the regex is now properly detecting key
|
||||
bindings with `-r` flag.
|
||||
- enable `aggressive-resize`
|
||||
|
||||
### v2.1.0, 2014-12-12
|
||||
- check before binding `prefix + prefix` (@m1foley)
|
||||
- enable `focus-events`
|
||||
- deprecate 'almost sensible' feature. The reason for this is to focus the
|
||||
plugin on doing just one thing.
|
||||
|
||||
### v2.0.0, 2014-10-03
|
||||
- bugfix: prevent exiting tmux if 'reattach-to-user-namespace' is not installed
|
||||
- remove all mouse-related options
|
||||
- introduce 'almost sensible' setting and options
|
||||
|
||||
### v1.1.0, 2014-08-30
|
||||
- bugfix: determine the default shell from the $SHELL env var on OS X
|
||||
- set `mode-mouse on` by default
|
||||
- do not make any decision about the prefix, just enhance it
|
||||
- update `README.md`. List options set in the plugin.
|
||||
- do *not* set `mode-mouse on` by default because some users don't like it
|
||||
- if a user changes default prefix but binds `C-b` to something else, do not
|
||||
unbind `C-b`
|
||||
|
||||
### v1.0.0, 2014-07-30
|
||||
- initial work on the plugin
|
||||
- add readme
|
19
tmux/.tmux/plugins/tmux-sensible/LICENSE.md
Normal file
@ -0,0 +1,19 @@
|
||||
Copyright (C) 2014 Bruno Sutic
|
||||
|
||||
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:
|
||||
|
||||
The above copyright notice and this permission notice shall be included
|
||||
in all copies or substantial portions of the Software.
|
||||
|
||||
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.
|
114
tmux/.tmux/plugins/tmux-sensible/README.md
Normal file
@ -0,0 +1,114 @@
|
||||
# Tmux sensible
|
||||
|
||||
A set of tmux options that should be acceptable to everyone.
|
||||
|
||||
Inspired by [vim-sensible](https://github.com/tpope/vim-sensible).
|
||||
|
||||
Tested and working on Linux, OSX and Cygwin.
|
||||
|
||||
### Principles
|
||||
|
||||
- `tmux-sensible` options should be acceptable to **every** tmux user!<br/>
|
||||
If any of the options bothers you, please open an issue and it will probably
|
||||
be updated (or removed).
|
||||
- if you think a new option should be added, feel free to open a pull request.
|
||||
- **no overriding** of user defined settings.<br/>
|
||||
Your existing `.tmux.conf` settings are respected and they won't be changed.
|
||||
That way you can use `tmux-sensible` if you have a few specific options.
|
||||
|
||||
### Goals
|
||||
|
||||
- group standard tmux community options in one place
|
||||
- remove clutter from your `.tmux.conf`
|
||||
- educate new tmux users about basic options
|
||||
|
||||
### Options
|
||||
|
||||
# utf8 is on
|
||||
set -g utf8 on
|
||||
set -g status-utf8 on
|
||||
|
||||
# address vim mode switching delay (http://superuser.com/a/252717/65504)
|
||||
set -s escape-time 0
|
||||
|
||||
# increase scrollback buffer size
|
||||
set -g history-limit 50000
|
||||
|
||||
# tmux messages are displayed for 4 seconds
|
||||
set -g display-time 4000
|
||||
|
||||
# refresh 'status-left' and 'status-right' more often
|
||||
set -g status-interval 5
|
||||
|
||||
# set only on OS X where it's required
|
||||
set -g default-command "reattach-to-user-namespace -l $SHELL"
|
||||
|
||||
# upgrade $TERM
|
||||
set -g default-terminal "screen-256color"
|
||||
|
||||
# emacs key bindings in tmux command prompt (prefix + :) are better than
|
||||
# vi keys, even for vim users
|
||||
set -g status-keys emacs
|
||||
|
||||
# focus events enabled for terminals that support them
|
||||
set -g focus-events on
|
||||
|
||||
# super useful when using "grouped sessions" and multi-monitor setup
|
||||
setw -g aggressive-resize on
|
||||
|
||||
### Key bindings
|
||||
|
||||
# easier and faster switching between next/prev window
|
||||
bind C-p previous-window
|
||||
bind C-n next-window
|
||||
|
||||
Above bindings enhance the default `prefix + p` and `prefix + n` bindings by
|
||||
allowing you to hold `Ctrl` and repeat `a + p`/`a + n` (if your prefix is
|
||||
`C-a`), which is a lot quicker.
|
||||
|
||||
# source .tmux.conf as suggested in `man tmux`
|
||||
bind R source-file '~/.tmux.conf'
|
||||
|
||||
"Adaptable" key bindings that build upon your `prefix` value:
|
||||
|
||||
# if prefix is 'C-a'
|
||||
bind C-a send-prefix
|
||||
bind a last-window
|
||||
|
||||
If prefix is `C-b`, above keys will be `C-b` and `b`.<br/>
|
||||
If prefix is `C-z`, above keys will be `C-z` and `z`... you get the idea.
|
||||
|
||||
### Installation with [Tmux Plugin Manager](https://github.com/tmux-plugins/tpm) (recommended)
|
||||
|
||||
Add plugin to the list of TPM plugins in `.tmux.conf`:
|
||||
|
||||
set -g @plugin 'tmux-plugins/tmux-sensible'
|
||||
|
||||
Hit `prefix + I` to fetch the plugin and source it. That's it!
|
||||
|
||||
### Manual Installation
|
||||
|
||||
Clone the repo:
|
||||
|
||||
$ git clone https://github.com/tmux-plugins/tmux-sensible ~/clone/path
|
||||
|
||||
Add this line to the bottom of `.tmux.conf`:
|
||||
|
||||
run-shell ~/clone/path/sensible.tmux
|
||||
|
||||
Reload TMUX environment with `$ tmux source-file ~/.tmux.conf`, and that's it.
|
||||
|
||||
### Other goodies
|
||||
|
||||
You might also find these useful:
|
||||
|
||||
- [copycat](https://github.com/tmux-plugins/tmux-copycat)
|
||||
improve tmux search and reduce mouse usage
|
||||
- [pain control](https://github.com/tmux-plugins/tmux-pain-control)
|
||||
useful standard bindings for controlling panes
|
||||
- [resurrect](https://github.com/tmux-plugins/tmux-resurrect)
|
||||
persists tmux environment across system restarts
|
||||
|
||||
### License
|
||||
|
||||
[MIT](LICENSE.md)
|
161
tmux/.tmux/plugins/tmux-sensible/sensible.tmux
Normal file
@ -0,0 +1,161 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
# used to match output from `tmux list-keys`
|
||||
KEY_BINDING_REGEX="bind-key[[:space:]]\+\(-r[[:space:]]\+\)\?\(-T prefix[[:space:]]\+\)\?"
|
||||
|
||||
is_osx() {
|
||||
local platform=$(uname)
|
||||
[ "$platform" == "Darwin" ]
|
||||
}
|
||||
|
||||
iterm_terminal() {
|
||||
[[ "$TERM_PROGRAM" =~ ^iTerm ]]
|
||||
}
|
||||
|
||||
command_exists() {
|
||||
local command="$1"
|
||||
type "$command" >/dev/null 2>&1
|
||||
}
|
||||
|
||||
# returns prefix key, e.g. 'C-a'
|
||||
prefix() {
|
||||
tmux show-option -gv prefix
|
||||
}
|
||||
|
||||
# if prefix is 'C-a', this function returns 'a'
|
||||
prefix_without_ctrl() {
|
||||
local prefix="$(prefix)"
|
||||
echo "$prefix" | cut -d '-' -f2
|
||||
}
|
||||
|
||||
option_value_not_changed() {
|
||||
local option="$1"
|
||||
local default_value="$2"
|
||||
local option_value=$(tmux show-option -gv "$option")
|
||||
[ "$option_value" == "$default_value" ]
|
||||
}
|
||||
|
||||
server_option_value_not_changed() {
|
||||
local option="$1"
|
||||
local default_value="$2"
|
||||
local option_value=$(tmux show-option -sv "$option")
|
||||
[ "$option_value" == "$default_value" ]
|
||||
}
|
||||
|
||||
key_binding_not_set() {
|
||||
local key="$1"
|
||||
if $(tmux list-keys | grep -q "${KEY_BINDING_REGEX}${key}[[:space:]]"); then
|
||||
return 1
|
||||
else
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
|
||||
key_binding_not_changed() {
|
||||
local key="$1"
|
||||
local default_value="$2"
|
||||
if $(tmux list-keys | grep -q "${KEY_BINDING_REGEX}${key}[[:space:]]\+${default_value}"); then
|
||||
# key still has the default binding
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
main() {
|
||||
# OPTIONS
|
||||
|
||||
# enable utf8 (option removed in tmux 2.2)
|
||||
tmux set-option -g utf8 on 2>/dev/null
|
||||
|
||||
# enable utf8 in tmux status-left and status-right (option removed in tmux 2.2)
|
||||
tmux set-option -g status-utf8 on 2>/dev/null
|
||||
|
||||
# address vim mode switching delay (http://superuser.com/a/252717/65504)
|
||||
if server_option_value_not_changed "escape-time" "500"; then
|
||||
tmux set-option -s escape-time 0
|
||||
fi
|
||||
|
||||
# increase scrollback buffer size
|
||||
if option_value_not_changed "history-limit" "2000"; then
|
||||
tmux set-option -g history-limit 50000
|
||||
fi
|
||||
|
||||
# tmux messages are displayed for 4 seconds
|
||||
if option_value_not_changed "display-time" "750"; then
|
||||
tmux set-option -g display-time 4000
|
||||
fi
|
||||
|
||||
# refresh 'status-left' and 'status-right' more often
|
||||
if option_value_not_changed "status-interval" "15"; then
|
||||
tmux set-option -g status-interval 5
|
||||
fi
|
||||
|
||||
# required (only) on OS X
|
||||
if is_osx && command_exists "reattach-to-user-namespace" && option_value_not_changed "default-command" ""; then
|
||||
tmux set-option -g default-command "reattach-to-user-namespace -l $SHELL"
|
||||
fi
|
||||
|
||||
# upgrade $TERM, tmux 1.9
|
||||
if option_value_not_changed "default-terminal" "screen"; then
|
||||
tmux set-option -g default-terminal "screen-256color"
|
||||
fi
|
||||
# upgrade $TERM, tmux 2.0+
|
||||
if server_option_value_not_changed "default-terminal" "screen"; then
|
||||
tmux set-option -s default-terminal "screen-256color"
|
||||
fi
|
||||
|
||||
# emacs key bindings in tmux command prompt (prefix + :) are better than
|
||||
# vi keys, even for vim users
|
||||
tmux set-option -g status-keys emacs
|
||||
|
||||
# focus events enabled for terminals that support them
|
||||
tmux set-option -g focus-events on
|
||||
|
||||
# super useful when using "grouped sessions" and multi-monitor setup
|
||||
if ! iterm_terminal; then
|
||||
tmux set-window-option -g aggressive-resize on
|
||||
fi
|
||||
|
||||
# DEFAULT KEY BINDINGS
|
||||
|
||||
local prefix="$(prefix)"
|
||||
local prefix_without_ctrl="$(prefix_without_ctrl)"
|
||||
|
||||
# if C-b is not prefix
|
||||
if [ $prefix != "C-b" ]; then
|
||||
# unbind obsolete default binding
|
||||
if key_binding_not_changed "C-b" "send-prefix"; then
|
||||
tmux unbind-key C-b
|
||||
fi
|
||||
|
||||
# pressing `prefix + prefix` sends <prefix> to the shell
|
||||
if key_binding_not_set "$prefix"; then
|
||||
tmux bind-key "$prefix" send-prefix
|
||||
fi
|
||||
fi
|
||||
|
||||
# If Ctrl-a is prefix then `Ctrl-a + a` switches between alternate windows.
|
||||
# Works for any prefix character.
|
||||
if key_binding_not_set "$prefix_without_ctrl"; then
|
||||
tmux bind-key "$prefix_without_ctrl" last-window
|
||||
fi
|
||||
|
||||
# easier switching between next/prev window
|
||||
if key_binding_not_set "C-p"; then
|
||||
tmux bind-key C-p previous-window
|
||||
fi
|
||||
if key_binding_not_set "C-n"; then
|
||||
tmux bind-key C-n next-window
|
||||
fi
|
||||
|
||||
# source `.tmux.conf` file - as suggested in `man tmux`
|
||||
if key_binding_not_set "R"; then
|
||||
tmux bind-key R run-shell ' \
|
||||
tmux source-file ~/.tmux.conf > /dev/null; \
|
||||
tmux display-message "Sourced .tmux.conf!"'
|
||||
fi
|
||||
}
|
||||
main
|
24
tmux/.tmux/plugins/tmux-yank/.editorconfig
Normal file
@ -0,0 +1,24 @@
|
||||
# EditorConfig: http://EditorConfig.org
|
||||
|
||||
root = true
|
||||
|
||||
[*]
|
||||
end_of_line = lf
|
||||
insert_final_newline = true
|
||||
charset = utf-8
|
||||
|
||||
[*.md]
|
||||
max_line_length = 76
|
||||
indent_size = 4
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
[Vagrantfile]
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
|
||||
[{*.sh,*.tmux}]
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
trim_trailing_whitespace = true
|
11
tmux/.tmux/plugins/tmux-yank/.gitattributes
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
# The linguist directives are for https://github.com/github/linguist
|
||||
|
||||
*.md text eol=lf whitespace=blank-at-eol
|
||||
*.sh text eol=lf whitespace=blank-at-eol diff=php
|
||||
*.tmux text eol=lf whitespace=blank-at-eol diff=php
|
||||
|
||||
Vagrantfile text eol=lf linguist-vendored
|
||||
video/* linguist-documentation
|
||||
|
||||
# Binary Types
|
||||
*.png binary
|
1
tmux/.tmux/plugins/tmux-yank/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
.vagrant/
|
17
tmux/.tmux/plugins/tmux-yank/.travis.yml
Normal file
@ -0,0 +1,17 @@
|
||||
sudo: required
|
||||
language: bash
|
||||
services:
|
||||
- docker
|
||||
|
||||
script:
|
||||
- "./citest"
|
||||
|
||||
notifications:
|
||||
email: false
|
||||
pushover:
|
||||
on_success: change
|
||||
on_failure: always
|
||||
api_key:
|
||||
secure: gWoqAqGyBbO6mcKbHkt29jJZ7ElOfct2C5WPfliBARl8ImCE0HE6CEGdK25i29mjfIxXWp3HITsRawuauZDN8nCZ9srO+0wr7OWAcZuhDW6mDmKNLX2y4eR4lK21MsMpLIHqA48hYXkHVKSHR7TDG88A/0MRXoTb5gcuPDJMqPk=
|
||||
users:
|
||||
secure: dIUBBbi8R7cOcwBQ8guLsq+M8vBXcSAu9vKUVEqToSHoWap4fTl4QSZpyhzxLy6uSNRwg1u20xVSlEAPee2Z+efzZQtA0I9bRTkcAMbzH65+sWKgMsEMJoHrqlCr7FvX4c+UMW9sWlRLoH52oN3ilCQNy2beI8mWqE4gAGxD4aA=
|
132
tmux/.tmux/plugins/tmux-yank/CHANGELOG.md
Normal file
@ -0,0 +1,132 @@
|
||||
Change Log
|
||||
==========
|
||||
|
||||
[master]
|
||||
--------
|
||||
|
||||
### Added
|
||||
|
||||
- Mouse support, controlled by `yank_with_mouse` and `yank_selection_mouse`
|
||||
(@keidax)
|
||||
|
||||
[v2.3.0] 2018-02-01
|
||||
-------------------
|
||||
|
||||
### Added
|
||||
|
||||
- Tmux 2.4 support (@docwhat, @edi9999)
|
||||
- Windows Subsystem for Linux (WSL) support via `clip.exe` (@lukewang1024)
|
||||
- "copy pane current directory" feature (@bruno-)
|
||||
- `yank_line` and `yank_pane_pwd` fork to prevent xclip from hanging Tmux (@leoalekseyev)
|
||||
* `yank_line` no longer cares if you use emacs or vi in copy-mode.
|
||||
|
||||
### Fixed
|
||||
|
||||
- Detect git builds of tmux version ≥ 2.4 (@maximbaz PR#89)
|
||||
|
||||
[v2.2.0] 2015-10-12
|
||||
-------------------
|
||||
|
||||
### Added
|
||||
|
||||
- Support for custom copy command (if `xclip` and others aren't
|
||||
accessible, and you want to have your custom copy command)
|
||||
- Cygwin support via `putclip` command
|
||||
|
||||
[v2.1.0] 2015-06-17
|
||||
-------------------
|
||||
|
||||
### Added
|
||||
|
||||
- Add support for `xsel` on Linux (@ctjhoa)
|
||||
- Support for shell `vi` mode (@xnaveira)
|
||||
|
||||
### Updated
|
||||
|
||||
- Make `reattach-to-user-namespace` on OS X optional (@bosr)
|
||||
- Deprecate <kbd>Alt</kbd>–<kbd>y</kbd>
|
||||
|
||||
[v2.0.0] 2014-12-06
|
||||
-------------------
|
||||
|
||||
### Fixed
|
||||
|
||||
- Change copy mode "put selection" key binding to <kbd>Y</kbd> so that vi
|
||||
mode <kbd>Control</kbd>–<kbd>y</kbd> is not overridden.
|
||||
|
||||
[v1.0.0] 2014-12-06
|
||||
-------------------
|
||||
|
||||
### Added
|
||||
|
||||
- Show error message if plugin dependencies aren't installed.
|
||||
- Vagrant setup for manually testing Linux.
|
||||
|
||||
### Updated
|
||||
|
||||
- `README`
|
||||
- Related plugin list
|
||||
- Instructions on updating `xclip` for Linux.
|
||||
|
||||
### Removed
|
||||
|
||||
- The screen-cast is moved into `screencast` branch.
|
||||
|
||||
[v0.0.4] 2014-07-29
|
||||
-------------------
|
||||
|
||||
### Updated
|
||||
|
||||
- `README` documentation; including a screen-cast.
|
||||
|
||||
[v0.0.3] 2014-06-29
|
||||
-------------------
|
||||
|
||||
### Added
|
||||
|
||||
- Wait when doing "yank line" when using a remote shell (`ssh`, `mosh`) to
|
||||
ensure screen is updated.
|
||||
|
||||
### Fixed
|
||||
|
||||
- Handle `yank-line` when used on the last line of buffer: copy multiple
|
||||
lines.
|
||||
- `yank-line` never yanks 'newline' char for multiple-line commands in
|
||||
shell (this is actually tmux/bash bug).
|
||||
|
||||
### Updated
|
||||
|
||||
- Code cleanup.
|
||||
|
||||
[v0.0.2] 2014-06-25
|
||||
-------------------
|
||||
|
||||
### Updated
|
||||
|
||||
- `README`
|
||||
|
||||
### Added
|
||||
|
||||
- In OS X: Check if `reattach-to-user-namespace` is installed.
|
||||
- "copy current command line" feature.
|
||||
|
||||
[v0.0.1] 2014-06-24
|
||||
-------------------
|
||||
|
||||
- First working version.
|
||||
|
||||
Notes
|
||||
-----
|
||||
|
||||
This change log is kept in <http://keepachangelog.com/> format.
|
||||
|
||||
[master]: https://github.com/tmux-plugins/tmux-yank/compare/v2.3.0...HEAD
|
||||
[v2.3.0]: https://github.com/tmux-plugins/tmux-yank/compare/v2.2.0...v2.3.0
|
||||
[v2.2.0]: https://github.com/tmux-plugins/tmux-yank/compare/v2.1.0...v2.2.0
|
||||
[v2.1.0]: https://github.com/tmux-plugins/tmux-yank/compare/v2.0.0...v2.1.0
|
||||
[v2.0.0]: https://github.com/tmux-plugins/tmux-yank/compare/v1.0.0...v2.0.0
|
||||
[v1.0.0]: https://github.com/tmux-plugins/tmux-yank/compare/v0.0.4...v1.0.0
|
||||
[v0.0.4]: https://github.com/tmux-plugins/tmux-yank/compare/v0.0.3...v0.0.4
|
||||
[v0.0.3]: https://github.com/tmux-plugins/tmux-yank/compare/v0.0.2...v0.0.3
|
||||
[v0.0.2]: https://github.com/tmux-plugins/tmux-yank/compare/v0.0.1...v0.0.2
|
||||
[v0.0.1]: https://github.com/tmux-plugins/tmux-yank/commits/v0.0.1
|
20
tmux/.tmux/plugins/tmux-yank/LICENSE.md
Normal file
@ -0,0 +1,20 @@
|
||||
Copyright (C) 2014, 2017 Bruno Sutic
|
||||
Copyright (C) 2017 Christian Höltje
|
||||
|
||||
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:
|
||||
|
||||
The above copyright notice and this permission notice shall be included
|
||||
in all copies or substantial portions of the Software.
|
||||
|
||||
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.
|
288
tmux/.tmux/plugins/tmux-yank/README.md
Normal file
@ -0,0 +1,288 @@
|
||||
[](https://travis-ci.org/tmux-plugins/tmux-yank)
|
||||
[](https://github.com/tmux-plugins/tmux-yank/releases)
|
||||
[](https://github.com/tmux-plugins/tmux-yank/issues)
|
||||
|
||||
tmux-yank
|
||||
=========
|
||||
|
||||
Copy to the system clipboard in [`tmux`](https://tmux.github.io/).
|
||||
|
||||
Supports:
|
||||
|
||||
- Linux
|
||||
- macOS
|
||||
- Cygwin
|
||||
- Windows Subsystem for Linux (WSL)
|
||||
|
||||
Installing
|
||||
----------
|
||||
|
||||
### Via TPM (recommended)
|
||||
|
||||
The easiest way to install `tmux-yank` is via the [Tmux Plugin
|
||||
Manager](https://github.com/tmux-plugins/tpm).
|
||||
|
||||
1. Add plugin to the list of TPM plugins in `.tmux.conf`:
|
||||
|
||||
``` tmux
|
||||
set -g @plugin 'tmux-plugins/tmux-yank'
|
||||
```
|
||||
|
||||
2. Use <kbd>prefix</kbd>–<kbd>I</kbd> install `tmux-yank`. You should now
|
||||
be able to `tmux-yank` immediately.
|
||||
3. When you want to update `tmux-yank` use <kbd>prefix</kbd>–<kbd>U</kbd>.
|
||||
|
||||
### Manual Installation
|
||||
|
||||
1. Clone the repository
|
||||
|
||||
``` sh
|
||||
$ git clone https://github.com/tmux-plugins/tmux-yank ~/clone/path
|
||||
```
|
||||
|
||||
2. Add this line to the bottom of `.tmux.conf`
|
||||
|
||||
``` tmux
|
||||
run-shell ~/clone/path/yank.tmux
|
||||
```
|
||||
|
||||
3. Reload the `tmux` environment
|
||||
|
||||
``` sh
|
||||
# type this inside tmux
|
||||
$ tmux source-file ~/.tmux.conf
|
||||
```
|
||||
|
||||
You should now be able to use `tmux-yank` immediately.
|
||||
|
||||
Requirements
|
||||
------------
|
||||
|
||||
In order for `tmux-yank` to work, there must be a program that store data in
|
||||
the system clipboard.
|
||||
|
||||
### macOS
|
||||
|
||||
- [`reattach-to-user-namespace`](https://github.com/ChrisJohnsen/tmux-MacOSX-pasteboard)
|
||||
|
||||
**Note**: Some versions of macOS (aka OS X) have been reported to work
|
||||
without `reattach-to-user-namespace`. It doesn't hurt to have it installed.
|
||||
|
||||
- OS X 10.8: Mountain Lion – *required*
|
||||
- OS X 10.9: Mavericks – *required*
|
||||
- OS X 10.10: Yosemite – *not required*
|
||||
- OS X 10.11: El Capitan – *not required*
|
||||
- macOS 10.12: Sierra – *required*
|
||||
|
||||
The easiest way to use `reattach-to-user-namespace` with `tmux` is use to
|
||||
use the [`tmux-sensible`](https://github.com/tmux-plugins/tmux-sensible)
|
||||
plugin.
|
||||
|
||||
To use it manually, use:
|
||||
|
||||
``` tmux
|
||||
# ~/.tmux.conf
|
||||
set-option -g default-command "reattach-to-user-namespace -l $SHELL"
|
||||
```
|
||||
|
||||
If you have `tmux` 1.5 or newer and are using
|
||||
[iTerm2](https://www.iterm2.com/) version 3 or newer then the <kbd>y</kbd>
|
||||
in `copy-mode` and mouse selection will work without `tmux-yank`.
|
||||
|
||||
To enable this:
|
||||
|
||||
1. Go into iTerm2's preferences.
|
||||
2. Go to the "General" tab.
|
||||
3. Check "Applications in terminal may access clipboard"
|
||||
4. In `tmux`, ensure `set-clipboard` is turned on:
|
||||
|
||||
``` sh
|
||||
$ tmux show-options -g -s set-clipboard
|
||||
set-clipboard on
|
||||
```
|
||||
|
||||
#### [HomeBrew](https://brew.sh/) (recommended)
|
||||
|
||||
``` sh
|
||||
$ brew install reattach-to-user-namespace
|
||||
```
|
||||
|
||||
#### MacPorts
|
||||
|
||||
``` sh
|
||||
$ sudo port install tmux-pasteboard
|
||||
```
|
||||
|
||||
### Linux
|
||||
|
||||
- `xsel` (recommended) or `xclip` (for X).
|
||||
- `wl-copy` from [wl-clipboard](https://github.com/bugaevc/wl-clipboard) (for Wayland)
|
||||
|
||||
If you have `tmux` 1.5 or newer and are using `xterm`, the <kbd>y</kbd> in
|
||||
`copy-mode` and mouse selection will work without `tmux-yank`. See the
|
||||
`tmux(1)` man page entry for the `set-clipboard` option.
|
||||
|
||||
#### Debian & Ubuntu
|
||||
|
||||
``` sh
|
||||
$ sudo apt-get install xsel # or xclip
|
||||
```
|
||||
|
||||
#### RedHat & CentOS
|
||||
|
||||
``` sh
|
||||
$ sudo yum install xsel # or xclip
|
||||
```
|
||||
|
||||
### Cygwin
|
||||
|
||||
- (*optional*) `putclip` which is part of the `cygutils-extra` package.
|
||||
|
||||
### Windows Subsystem for Linux (WSL)
|
||||
|
||||
- `clip.exe` is shipped with Windows Subsystem for Linux.
|
||||
|
||||
Configuration
|
||||
-------------
|
||||
|
||||
### Key bindings
|
||||
|
||||
- Normal Mode
|
||||
- <kbd>prefix</kbd>–<kbd>y</kbd> — copies text from the command line
|
||||
to the clipboard.
|
||||
|
||||
Works with all popular shells/repls. Tested with:
|
||||
|
||||
- shells: `bash`, `zsh` (with `bindkey -e`), `tcsh`
|
||||
- repls: `irb`, `pry`, `node`, `psql`, `python`, `php -a`,
|
||||
`coffee`
|
||||
- remote shells: `ssh`, [mosh](http://mosh.mit.edu/)
|
||||
- vim/neovim command line (requires
|
||||
[vim-husk](https://github.com/bruno-/vim-husk) or
|
||||
[vim-rsi](https://github.com/tpope/vim-rsi) plugin)
|
||||
|
||||
- <kbd>prefix</kbd>–<kbd>Y</kbd> — copy the current pane's current
|
||||
working directory to the clipboard.
|
||||
|
||||
- Copy Mode
|
||||
- <kbd>y</kbd> — copy selection to system clipboard.
|
||||
- <kbd>Y</kbd> (shift-y) — "put" selection. Equivalent to copying a
|
||||
selection, and pasting it to the command line.
|
||||
|
||||
|
||||
### Default and Preferred Clipboard Programs
|
||||
|
||||
tmux-yank does its best to detect a reasonable choice for a clipboard
|
||||
program on your OS.
|
||||
|
||||
If tmux-yank can't detect a known clipboard program then it uses the
|
||||
`@custom_copy_command` tmux option as your clipboard program if set.
|
||||
|
||||
If you need to always override tmux-yank's choice for a clipboard program,
|
||||
then you can set `@override_copy_command` to force tmux-yank to use whatever
|
||||
you want.
|
||||
|
||||
Note that both programs _must_ accept `STDIN` for the text to be copied.
|
||||
|
||||
An example of setting `@override_copy_command`:
|
||||
|
||||
``` tmux
|
||||
# ~/.tmux.conf
|
||||
|
||||
set -g @custom_copy_command 'my-clipboard-copy --some-arg'
|
||||
# or
|
||||
set -g @override_copy_command 'my-clipboard-copy --some-arg'
|
||||
```
|
||||
|
||||
### Linux Clipboards
|
||||
|
||||
Linux has several cut-and-paste clipboards: `primary`, `secondary`, and
|
||||
`clipboard` (default in tmux-yank is `clipboard`).
|
||||
|
||||
You can change this by setting `@yank_selection`:
|
||||
|
||||
``` tmux
|
||||
# ~/.tmux.conf
|
||||
|
||||
set -g @yank_selection 'primary' # or 'secondary' or 'clipboard'
|
||||
```
|
||||
|
||||
With mouse support turned on (see below) the default clipboard for mouse
|
||||
selections is `primary`.
|
||||
|
||||
You can change this by setting `@yank_selection_mouse`:
|
||||
|
||||
``` tmux
|
||||
# ~/.tmux.conf
|
||||
|
||||
set -g @yank_selection_mouse 'clipboard' # or 'primary' or 'secondary'
|
||||
```
|
||||
|
||||
### Controlling Yank Behavior
|
||||
|
||||
By default, `tmux-yank` will exit copy mode after yanking text. If you wish to
|
||||
remain in copy mode, you can set `@yank_action`:
|
||||
|
||||
``` tmux
|
||||
# ~/.tmux.conf
|
||||
|
||||
set -g @yank_action 'copy-pipe' # or 'copy-pipe-and-cancel' for the default
|
||||
```
|
||||
|
||||
### Mouse Support
|
||||
|
||||
`tmux-yank` has mouse support enabled by default. It will only work if `tmux`'s
|
||||
built-in mouse support is also enabled (with `mouse on` since `tmux` 2.1, or
|
||||
`mode-mouse on` in older versions).
|
||||
|
||||
To yank with the mouse, click and drag with the primary button to begin
|
||||
selection, and release to yank.
|
||||
|
||||
If you would prefer to disable this behavior, or provide your own bindings for
|
||||
the `MouseDragEnd1Pane` event, you can do so with:
|
||||
|
||||
``` tmux
|
||||
# ~/.tmux.conf
|
||||
|
||||
set -g @yank_with_mouse off # or 'on'
|
||||
```
|
||||
|
||||
If you want to remain in copy mode after making a mouse selection, set
|
||||
`@yank_action` as described above.
|
||||
|
||||
### vi mode support
|
||||
|
||||
If using `tmux` 2.3 or older *and* using vi keys then you'll have add the
|
||||
following configuration setting:
|
||||
|
||||
``` tmux
|
||||
# ~/.tmux.conf
|
||||
|
||||
set -g @shell_mode 'vi'
|
||||
```
|
||||
|
||||
This isn't needed with `tmux` 2.4 or newer.
|
||||
|
||||
### Screen-cast
|
||||
|
||||
[](https://vimeo.com/102039099)
|
||||
|
||||
**Note**: The screen-cast uses <kbd>Control</kbd>–<kbd>y</kbd> for
|
||||
"put selection". Use <kbd>Y</kbd> in `v2.0.0` and later.
|
||||
|
||||
### Other tmux plugins
|
||||
|
||||
- [tmux-copycat](https://github.com/tmux-plugins/tmux-copycat) - a plugin
|
||||
for regular expression searches in tmux and fast match selection
|
||||
- [tmux-open](https://github.com/tmux-plugins/tmux-open) - a plugin for
|
||||
quickly opening highlighted file or a URL
|
||||
- [tmux-continuum](https://github.com/tmux-plugins/tmux-continuum) -
|
||||
automatic restoring and continuous saving of tmux environment.
|
||||
|
||||
### License
|
||||
|
||||
[MIT](LICENSE.md)
|
10
tmux/.tmux/plugins/tmux-yank/Vagrantfile
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
VAGRANTFILE_API_VERSION = '2'
|
||||
|
||||
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
|
||||
config.vm.box = 'precise32'
|
||||
config.vm.box_url = 'http://files.vagrantup.com/precise32.box'
|
||||
|
||||
config.vm.provision 'shell', path: 'vagrant_provisioning.sh'
|
||||
|
||||
config.ssh.forward_x11 = true
|
||||
end
|
1
tmux/.tmux/plugins/tmux-yank/_config.yml
Normal file
@ -0,0 +1 @@
|
||||
theme: jekyll-theme-slate
|
30
tmux/.tmux/plugins/tmux-yank/citest
Normal file
@ -0,0 +1,30 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
cd "$(dirname "$0")"
|
||||
|
||||
bash_scripts=(
|
||||
yank.tmux
|
||||
scripts/*.sh
|
||||
)
|
||||
|
||||
set -x
|
||||
docker run \
|
||||
--rm \
|
||||
--volume="${PWD}:/mnt:ro" \
|
||||
--workdir="/mnt" \
|
||||
bash:latest \
|
||||
bash -Dn "${bash_scripts[@]}"
|
||||
|
||||
docker run \
|
||||
--rm \
|
||||
--volume="${PWD}:/mnt:ro" \
|
||||
--workdir="/mnt" \
|
||||
koalaman/shellcheck:stable \
|
||||
--shell=bash \
|
||||
--external-sources \
|
||||
--color=always \
|
||||
"${bash_scripts[@]}"
|
||||
|
||||
# EOF
|
111
tmux/.tmux/plugins/tmux-yank/scripts/copy_line.sh
Normal file
@ -0,0 +1,111 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
HELPERS_DIR="$CURRENT_DIR"
|
||||
TMUX_COPY_MODE=""
|
||||
|
||||
REMOTE_SHELL_WAIT_TIME="0.4"
|
||||
|
||||
# shellcheck source=scripts/helpers.sh
|
||||
source "${HELPERS_DIR}/helpers.sh"
|
||||
|
||||
# sets a TMUX_COPY_MODE that is used as a global variable
|
||||
get_tmux_copy_mode() {
|
||||
TMUX_COPY_MODE="$(tmux show-option -gwv mode-keys)"
|
||||
}
|
||||
|
||||
# The command when on ssh with latency. To make it work in this case too,
|
||||
# sleep is added.
|
||||
add_sleep_for_remote_shells() {
|
||||
local pane_command
|
||||
pane_command="$(tmux display-message -p '#{pane_current_command}')"
|
||||
if [[ $pane_command =~ (ssh|mosh) ]]; then
|
||||
sleep "$REMOTE_SHELL_WAIT_TIME"
|
||||
fi
|
||||
}
|
||||
|
||||
go_to_the_beginning_of_current_line() {
|
||||
if [ "$(shell_mode)" == "emacs" ]; then
|
||||
tmux send-key 'C-a'
|
||||
else
|
||||
tmux send-key 'Escape' '0'
|
||||
fi
|
||||
}
|
||||
|
||||
enter_tmux_copy_mode() {
|
||||
tmux copy-mode
|
||||
}
|
||||
|
||||
start_tmux_selection() {
|
||||
if tmux_is_at_least 2.4; then
|
||||
tmux send -X begin-selection
|
||||
elif [ "$TMUX_COPY_MODE" == "vi" ]; then
|
||||
# vi copy mode
|
||||
tmux send-key 'Space'
|
||||
else
|
||||
# emacs copy mode
|
||||
tmux send-key 'C-Space'
|
||||
fi
|
||||
}
|
||||
|
||||
# works when command spans accross multiple lines
|
||||
end_of_line_in_copy_mode() {
|
||||
if tmux_is_at_least 2.4; then
|
||||
tmux send -X -N 150 'cursor-down' # 'down' key. 'vi' mode is faster so we're
|
||||
# jumping more lines than emacs.
|
||||
tmux send -X 'end-of-line' # End of line (just in case we are already at the last line).
|
||||
tmux send -X 'previous-word' # Beginning of the previous word.
|
||||
tmux send -X 'next-word-end' # End of next word.
|
||||
elif [ "$TMUX_COPY_MODE" == "vi" ]; then
|
||||
# vi copy mode
|
||||
# This sequence of keys consistently selects multiple lines
|
||||
tmux send-key '150' # Go to the bottom of scrollback buffer by using
|
||||
tmux send-key 'j' # 'down' key. 'vi' mode is faster so we're
|
||||
# jumping more lines than emacs.
|
||||
tmux send-key '$' # End of line (just in case we are already at the last line).
|
||||
tmux send-key 'b' # Beginning of the previous word.
|
||||
tmux send-key 'e' # End of next word.
|
||||
else
|
||||
# emacs copy mode
|
||||
for ((c = 1; c <= '30'; c++)); do # go to the bottom of scrollback buffer
|
||||
tmux send-key 'C-n'
|
||||
done
|
||||
tmux send-key 'C-e'
|
||||
tmux send-key 'M-b'
|
||||
tmux send-key 'M-f'
|
||||
fi
|
||||
}
|
||||
|
||||
yank_to_clipboard() {
|
||||
if tmux_is_at_least 2.4; then
|
||||
# shellcheck disable=SC2119
|
||||
tmux send -X copy-pipe-and-cancel "$(clipboard_copy_command)"
|
||||
else
|
||||
tmux send-key "$(yank_wo_newline_key)"
|
||||
fi
|
||||
}
|
||||
|
||||
go_to_the_end_of_current_line() {
|
||||
if [ "$(shell_mode)" == "emacs" ]; then
|
||||
tmux send-keys 'C-e'
|
||||
else
|
||||
tmux send-keys '$' 'a'
|
||||
fi
|
||||
}
|
||||
|
||||
yank_current_line() {
|
||||
go_to_the_beginning_of_current_line
|
||||
add_sleep_for_remote_shells
|
||||
enter_tmux_copy_mode
|
||||
start_tmux_selection
|
||||
end_of_line_in_copy_mode
|
||||
yank_to_clipboard
|
||||
go_to_the_end_of_current_line
|
||||
display_message 'Line copied to clipboard!'
|
||||
}
|
||||
|
||||
main() {
|
||||
get_tmux_copy_mode
|
||||
yank_current_line
|
||||
}
|
||||
main
|
25
tmux/.tmux/plugins/tmux-yank/scripts/copy_pane_pwd.sh
Normal file
@ -0,0 +1,25 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
HELPERS_DIR="$CURRENT_DIR"
|
||||
|
||||
# shellcheck source=scripts/helpers.sh
|
||||
source "${HELPERS_DIR}/helpers.sh"
|
||||
|
||||
pane_current_path() {
|
||||
tmux display -p -F "#{pane_current_path}"
|
||||
}
|
||||
|
||||
display_notice() {
|
||||
display_message 'PWD copied to clipboard!'
|
||||
}
|
||||
|
||||
main() {
|
||||
local copy_command
|
||||
# shellcheck disable=SC2119
|
||||
copy_command="$(clipboard_copy_command)"
|
||||
# $copy_command below should not be quoted
|
||||
pane_current_path | tr -d '\n' | $copy_command
|
||||
display_notice
|
||||
}
|
||||
main
|
205
tmux/.tmux/plugins/tmux-yank/scripts/helpers.sh
Normal file
@ -0,0 +1,205 @@
|
||||
#!bash
|
||||
# shellcheck disable=SC2239
|
||||
|
||||
yank_line="y"
|
||||
yank_line_option="@yank_line"
|
||||
|
||||
yank_pane_pwd="Y"
|
||||
yank_pane_pwd_option="@yank_pane_pwd"
|
||||
|
||||
yank_default="y"
|
||||
yank_option="@copy_mode_yank"
|
||||
|
||||
put_default="Y"
|
||||
put_option="@copy_mode_put"
|
||||
|
||||
yank_put_default="M-y"
|
||||
yank_put_option="@copy_mode_yank_put"
|
||||
|
||||
yank_wo_newline_default="!"
|
||||
yank_wo_newline_option="@copy_mode_yank_wo_newline"
|
||||
|
||||
yank_selection_default="clipboard"
|
||||
yank_selection_option="@yank_selection"
|
||||
|
||||
yank_selection_mouse_default="primary"
|
||||
yank_selection_mouse_option="@yank_selection_mouse"
|
||||
|
||||
yank_with_mouse_default="on"
|
||||
yank_with_mouse_option="@yank_with_mouse"
|
||||
|
||||
yank_action_default="copy-pipe-and-cancel"
|
||||
yank_action_option="@yank_action"
|
||||
|
||||
shell_mode_default="emacs"
|
||||
shell_mode_option="@shell_mode"
|
||||
|
||||
custom_copy_command_default=""
|
||||
custom_copy_command_option="@custom_copy_command"
|
||||
|
||||
override_copy_command_default=""
|
||||
override_copy_command_option="@override_copy_command"
|
||||
|
||||
# helper functions
|
||||
get_tmux_option() {
|
||||
local option="$1"
|
||||
local default_value="$2"
|
||||
local option_value
|
||||
option_value=$(tmux show-option -gqv "$option")
|
||||
if [ -z "$option_value" ]; then
|
||||
echo "$default_value"
|
||||
else
|
||||
echo "$option_value"
|
||||
fi
|
||||
}
|
||||
|
||||
yank_line_key() {
|
||||
get_tmux_option "$yank_line_option" "$yank_line"
|
||||
}
|
||||
|
||||
yank_pane_pwd_key() {
|
||||
get_tmux_option "$yank_pane_pwd_option" "$yank_pane_pwd"
|
||||
}
|
||||
|
||||
yank_key() {
|
||||
get_tmux_option "$yank_option" "$yank_default"
|
||||
}
|
||||
|
||||
put_key() {
|
||||
get_tmux_option "$put_option" "$put_default"
|
||||
}
|
||||
|
||||
yank_put_key() {
|
||||
get_tmux_option "$yank_put_option" "$yank_put_default"
|
||||
}
|
||||
|
||||
yank_wo_newline_key() {
|
||||
get_tmux_option "$yank_wo_newline_option" "$yank_wo_newline_default"
|
||||
}
|
||||
|
||||
yank_selection() {
|
||||
get_tmux_option "$yank_selection_option" "$yank_selection_default"
|
||||
}
|
||||
|
||||
yank_selection_mouse() {
|
||||
get_tmux_option "$yank_selection_mouse_option" "$yank_selection_mouse_default"
|
||||
}
|
||||
|
||||
yank_with_mouse() {
|
||||
get_tmux_option "$yank_with_mouse_option" "$yank_with_mouse_default"
|
||||
}
|
||||
|
||||
yank_action() {
|
||||
get_tmux_option "$yank_action_option" "$yank_action_default"
|
||||
}
|
||||
|
||||
shell_mode() {
|
||||
get_tmux_option "$shell_mode_option" "$shell_mode_default"
|
||||
}
|
||||
|
||||
custom_copy_command() {
|
||||
get_tmux_option "$custom_copy_command_option" "$custom_copy_command_default"
|
||||
}
|
||||
|
||||
override_copy_command() {
|
||||
get_tmux_option "$override_copy_command_option" "$override_copy_command_default"
|
||||
}
|
||||
# Ensures a message is displayed for 5 seconds in tmux prompt.
|
||||
# Does not override the 'display-time' tmux option.
|
||||
display_message() {
|
||||
local message="$1"
|
||||
|
||||
# display_duration defaults to 5 seconds, if not passed as an argument
|
||||
if [ "$#" -eq 2 ]; then
|
||||
local display_duration="$2"
|
||||
else
|
||||
local display_duration="5000"
|
||||
fi
|
||||
|
||||
# saves user-set 'display-time' option
|
||||
local saved_display_time
|
||||
saved_display_time=$(get_tmux_option "display-time" "750")
|
||||
|
||||
# sets message display time to 5 seconds
|
||||
tmux set-option -gq display-time "$display_duration"
|
||||
|
||||
# displays message
|
||||
tmux display-message "$message"
|
||||
|
||||
# restores original 'display-time' value
|
||||
tmux set-option -gq display-time "$saved_display_time"
|
||||
}
|
||||
|
||||
command_exists() {
|
||||
local command="$1"
|
||||
type "$command" >/dev/null 2>&1
|
||||
}
|
||||
|
||||
clipboard_copy_command() {
|
||||
local mouse="${1:-false}"
|
||||
# installing reattach-to-user-namespace is recommended on OS X
|
||||
if [ -n "$(override_copy_command)" ]; then
|
||||
override_copy_command
|
||||
elif command_exists "pbcopy"; then
|
||||
if command_exists "reattach-to-user-namespace"; then
|
||||
echo "reattach-to-user-namespace pbcopy"
|
||||
else
|
||||
echo "pbcopy"
|
||||
fi
|
||||
elif command_exists "clip.exe"; then # WSL clipboard command
|
||||
echo "cat | clip.exe"
|
||||
elif command_exists "wl-copy"; then # wl-clipboard: Wayland clipboard utilities
|
||||
echo "wl-copy"
|
||||
elif command_exists "xsel"; then
|
||||
local xsel_selection
|
||||
if [[ $mouse == "true" ]]; then
|
||||
xsel_selection="$(yank_selection_mouse)"
|
||||
else
|
||||
xsel_selection="$(yank_selection)"
|
||||
fi
|
||||
echo "xsel -i --$xsel_selection"
|
||||
elif command_exists "xclip"; then
|
||||
local xclip_selection
|
||||
if [[ $mouse == "true" ]]; then
|
||||
xclip_selection="$(yank_selection_mouse)"
|
||||
else
|
||||
xclip_selection="$(yank_selection)"
|
||||
fi
|
||||
echo "xclip -selection $xclip_selection"
|
||||
elif command_exists "putclip"; then # cygwin clipboard command
|
||||
echo "putclip"
|
||||
elif [ -n "$(custom_copy_command)" ]; then
|
||||
custom_copy_command
|
||||
fi
|
||||
}
|
||||
|
||||
# Cache the TMUX version for speed.
|
||||
tmux_version="$(tmux -V | cut -d ' ' -f 2)"
|
||||
|
||||
tmux_is_at_least() {
|
||||
if [[ $tmux_version == "$1" ]] || [[ $tmux_version == master ]]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
local i
|
||||
local -a current_version wanted_version
|
||||
IFS='.' read -ra current_version <<<"$tmux_version"
|
||||
IFS='.' read -ra wanted_version <<<"$1"
|
||||
|
||||
# fill empty fields in current_version with zeros
|
||||
for ((i = ${#current_version[@]}; i < ${#wanted_version[@]}; i++)); do
|
||||
current_version[i]=0
|
||||
done
|
||||
|
||||
# fill empty fields in wanted_version with zeros
|
||||
for ((i = ${#wanted_version[@]}; i < ${#current_version[@]}; i++)); do
|
||||
wanted_version[i]=0
|
||||
done
|
||||
|
||||
for ((i = 0; i < ${#current_version[@]}; i++)); do
|
||||
if ((10#${current_version[i]} < 10#${wanted_version[i]})); then
|
||||
return 1
|
||||
fi
|
||||
done
|
||||
return 0
|
||||
}
|
13
tmux/.tmux/plugins/tmux-yank/vagrant_provisioning.sh
Normal file
@ -0,0 +1,13 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y git-core expect vim xclip
|
||||
sudo apt-get install -y python-software-properties software-properties-common
|
||||
|
||||
# install latest Tmux 1.9a
|
||||
sudo add-apt-repository -y ppa:pi-rho/dev
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y tmux=1.9a-1~ppa1~p
|
||||
|
||||
# configure X11 for xclip testing
|
||||
echo "export DISPLAY='IP:0.0'" >>/home/vagrant/.bashrc
|
7
tmux/.tmux/plugins/tmux-yank/video/README.md
Normal file
@ -0,0 +1,7 @@
|
||||
## Tmux yank screencast
|
||||
|
||||
This directory contains docs used for creating
|
||||
[tmux yank screencast](https://vimeo.com/102039099).
|
||||
|
||||
- `script.md` - this file contains a script and a voiceover used to produce the
|
||||
screencast
|
BIN
tmux/.tmux/plugins/tmux-yank/video/screencast_img.png
Normal file
After Width: | Height: | Size: 52 KiB |
204
tmux/.tmux/plugins/tmux-yank/video/script.md
Normal file
@ -0,0 +1,204 @@
|
||||
# Tmux yank screencast script
|
||||
|
||||
1 - Intro - what's the plugin about
|
||||
===================================
|
||||
Actions
|
||||
-------
|
||||
- none, just clear screen
|
||||
|
||||
Script
|
||||
------
|
||||
In this screencast we'll demo a tmux yank plugin.
|
||||
|
||||
This plugin enables you to copy some text from tmux to the system clipboard,
|
||||
along with some extra functionality we'll show.
|
||||
It was made to complement tmux copycat plugin which we'll also be using for
|
||||
selection in this screencast.
|
||||
|
||||
2 - problems with vanilla tmux and `y`
|
||||
==============================
|
||||
Actions
|
||||
-------
|
||||
- $ echo 'example url https://github.com/tmux-plugins/tmux-yank'
|
||||
- highlight url
|
||||
- enter
|
||||
- paste url
|
||||
|
||||
- remove url
|
||||
- highlight url again
|
||||
- 'y'
|
||||
- paste with cmd + v
|
||||
|
||||
Script
|
||||
------
|
||||
Let's show a problem scenario you might be having with tmux.
|
||||
|
||||
I'll generate some example output with a url in the terminal.
|
||||
|
||||
Okay, now I want to copy that url and open it in the browser.
|
||||
By using tmux copycat saved search I'll quickly select the url.
|
||||
|
||||
I'll press enter, a "bajnding" for copy.
|
||||
I can now paste it in tmux by pressing prefix + right angle bracket.
|
||||
|
||||
That works, but there's a problem. Tmux paste works only within tmux. Pressing
|
||||
prefix + right angle bracket won't work in the browser where I actually want the
|
||||
above url to be.
|
||||
|
||||
|
||||
Ideally, when I copy some text in tmux, I want it to be available for paste
|
||||
anywhere on the system with control-v or command-v if I'm on a Mac.
|
||||
|
||||
Enter tmux-yank which enables just that.
|
||||
I'll select the url again.
|
||||
|
||||
Tmux-yank provides a convenient "bajnding" so that pressing 'y' in copy mode
|
||||
copies the text and makes it available in system clipboard.
|
||||
|
||||
I'm on a mac so I'll press command-v and there you have you have it.
|
||||
It goes without saying that this paste will work in the browser.
|
||||
|
||||
|
||||
Personally, I use tmux-yank copying all the time so I don't have to think in
|
||||
terms of being in tmux versus working with the rest of the system.
|
||||
|
||||
And also, this way I can avoid tmux default paste binding 'prefix + right angle
|
||||
bracket' because it is a bit clunky and unintuitive.
|
||||
|
||||
3 - showing 'ctrl-y'
|
||||
====================
|
||||
Actions
|
||||
-------
|
||||
- git status -sb (file1.txt, file2.txt, file3.txt)
|
||||
- git add
|
||||
- highlight last file
|
||||
- y
|
||||
- paste and enter to git add a file
|
||||
|
||||
- clear screen
|
||||
- git status -sb
|
||||
- git add
|
||||
- highlight last file
|
||||
- ctrl-y and git add a file
|
||||
|
||||
- cmd - v
|
||||
|
||||
Script
|
||||
------
|
||||
Let's show another feature.
|
||||
|
||||
I'll invoke git status command for the project I'm in.
|
||||
Now I want to git add only the last file.
|
||||
|
||||
I'll select the last file, yank and paste.
|
||||
|
||||
Do you think we can optimize this?
|
||||
|
||||
Often with tmux there's a need to copy a selection, and paste it to the command
|
||||
line immediately.
|
||||
|
||||
Tmux-yank provides a so called 'put selection' command. Let's demo it.
|
||||
|
||||
I'll highlight another git status file and press control-y.
|
||||
The selection is immediately 'put' to the command line. That's one step, instead
|
||||
of two.
|
||||
|
||||
|
||||
A nice side-effect of 'put selection' command is that it preserves the system
|
||||
clipboard content.
|
||||
If I press command-v now you'll see that the clipboard still contains the
|
||||
previous entry. 'put selection' command didn't overwrite it.
|
||||
|
||||
4. show 'line yank'
|
||||
===================
|
||||
Actions
|
||||
-------
|
||||
- clear pane scrollback
|
||||
- split window
|
||||
- echo 'some command'
|
||||
- ctrl-p to show the last command
|
||||
- prefix + y
|
||||
|
||||
- go the the pane on the right
|
||||
- cmd - v
|
||||
|
||||
Script
|
||||
------
|
||||
The last tmux-yank feature I'd like to show is 'line yank'.
|
||||
|
||||
It enables you to quickly copy the current command line to system clipoard.
|
||||
The nice thing is, it also works for commands that strech multiple lines.
|
||||
|
||||
But here's the basic example. I'll write a simple command.
|
||||
|
||||
Okay, that works. Now, I want to execute that same command in the pane on the
|
||||
right. I could of course type the command again, but that's tedious and I could
|
||||
make a typo.
|
||||
|
||||
Another solution is mouse selection, but that's just slow and lame.
|
||||
|
||||
|
||||
I'll use the 'line yank' feature.
|
||||
I'll press prefix + 'y' and the command is copied. Notice there were no changes
|
||||
to the command itself - it is intact.
|
||||
|
||||
In the second pane on the right I can paste the line with command - v.
|
||||
|
||||
5. show 'line yank' with the production server
|
||||
==============================================
|
||||
Actions
|
||||
-------
|
||||
- left pane - local psql console
|
||||
- right pane - psql console on developsta
|
||||
- prepared create_table command on the left
|
||||
- execute the command, it's ok
|
||||
- show the command again
|
||||
- show that mouse selection is innefective
|
||||
- prefix + y
|
||||
|
||||
- switch to right pane
|
||||
- paste
|
||||
- enter
|
||||
|
||||
Script
|
||||
------
|
||||
One scenario where I find line yank feature really useful is when I have to
|
||||
execute a command on the production server.
|
||||
|
||||
Here I have the local environment in the left pane, and I'm connected to
|
||||
the production server in the right pane.
|
||||
|
||||
The task I want to perform is creating a database table on the
|
||||
production server.
|
||||
Frankly, I feel hesitatnt to type that command straight on production.
|
||||
|
||||
I'd rather first try and debug it locally, and then execute it on production.
|
||||
|
||||
Let's do that then. I'll open a database console locally and type the command.
|
||||
|
||||
|
||||
Oh, it looks like I have a typo. It's good I tried this locally first.
|
||||
|
||||
Ok, the command works and is now ready. How do I now run in on production?
|
||||
Typing this again, with the possibility of making a typo is not an option.
|
||||
Let's try mouse selection.
|
||||
|
||||
Hm, that won't work either. It seems I can't scope mouse
|
||||
selection to the left pane.
|
||||
|
||||
Let's now try line yank with prefix + 'y'.
|
||||
Notice we're copying a multi-line command.
|
||||
|
||||
I'll paste it in the right pane.
|
||||
|
||||
That looks ok, so I'll execute it.. and it's good.
|
||||
|
||||
6. Outro
|
||||
========
|
||||
Actions
|
||||
-------
|
||||
- just a blank screen
|
||||
|
||||
Script
|
||||
------
|
||||
That's it for this screencast. I hope you'll find tmux-yank useful.
|