├── .github └── stale.yml ├── .gitmodules ├── .tmux-osx.conf ├── .tmux.conf ├── README.md ├── install.sh ├── scripts └── resize-adaptable.sh └── vendor └── basic-cpu-and-memory.tmux /.github/stale.yml: -------------------------------------------------------------------------------- 1 | # Number of days of inactivity before an issue becomes stale 2 | daysUntilStale: 60 3 | # Number of days of inactivity before a stale issue is closed 4 | daysUntilClose: 7 5 | # Issues with these labels will never be considered stale 6 | exemptLabels: 7 | - pinned 8 | - security 9 | # Label to use when marking an issue as stale 10 | staleLabel: stale 11 | # Comment to post when marking an issue as stale. Set to `false` to disable 12 | markComment: | 13 | This issue has been automatically marked as stale because it has not had 14 | recent activity. It will be closed if no further activity occurs. Thank you 15 | for your contributions. 16 | 17 | This bot is used to handle issues where the issue hasn't been discussed or 18 | has gone out of date. If an issue isn't resolved and handled in a certain 19 | period of time, it may be closed. If you would like your issue re-opened, 20 | please create a fresh issue with the latest, up to date information and 21 | mention this issue in it. 22 | unmarkComment: | 23 | Thank you for updating this issue. It is no longer marked as stale. 24 | 25 | # Comment to post when closing a stale issue. Set to `false` to disable 26 | closeComment: false 27 | 28 | # limit to only 'issues' or 'pulls' 29 | only: issues 30 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "vendor/tmux-mem-cpu-load"] 2 | path = vendor/tmux-mem-cpu-load 3 | url = https://github.com/thewtex/tmux-mem-cpu-load.git 4 | -------------------------------------------------------------------------------- /.tmux-osx.conf: -------------------------------------------------------------------------------- 1 | # https://github.com/ChrisJohnsen/tmux-MacOSX-pasteboard 2 | 3 | set-option -g default-command 'exec reattach-to-user-namespace -l zsh' 4 | bind-key C-c run-shell 'tmux save-buffer - | reattach-to-user-namespace pbcopy' 5 | bind-key C-v run-shell 'reattach-to-user-namespace pbpaste | tmux load-buffer - \; paste-buffer -d' 6 | bind-key -t vi-copy y 'reattach-to-user-namespace pbcopy' 7 | bind-key -t emacs-copy M-w 'reattach-to-user-namespace pbcopy' 8 | -------------------------------------------------------------------------------- /.tmux.conf: -------------------------------------------------------------------------------- 1 | # https://github.com/seebi/tmux-colors-solarized/blob/master/tmuxcolors-256.conf 2 | set-option -g status-style bg=colour235,fg=colour136,default # bg=base02, fg=yellow 3 | 4 | # easy reload config 5 | bind-key r source-file ~/.tmux.conf \; display-message "~/.tmux.conf reloaded." 6 | 7 | # set window split 8 | bind-key v split-window -h 9 | bind-key b split-window 10 | 11 | # default window title colors 12 | set-window-option -g window-status-style fg=colour244,bg=default,dim # fg=base0 13 | 14 | # active window title colors 15 | set-window-option -g window-status-current-style fg=colour166,bg=default,bright # fg=orange 16 | 17 | # pane border 18 | set-option -g pane-border-style fg=colour235 #fg=base02 19 | set-option -g pane-active-border-style fg=colour240 #fg=base01 20 | 21 | # message text 22 | set-option -g message-style bg=colour235,fg=colour166 # bg=base02, fg=orange 23 | 24 | # pane number display 25 | set-option -g display-panes-active-colour colour33 #blue 26 | set-option -g display-panes-colour colour166 #orange 27 | # clock 28 | set-window-option -g clock-mode-colour green #green 29 | 30 | 31 | set -g status-interval 1 32 | set -g status-justify centre # center align window list 33 | set -g status-left-length 20 34 | set -g status-right-length 140 35 | set -g status-left '#[fg=green]#H #[fg=black]• #[fg=green,bright]#(uname -r | cut -c 1-6)#[default]' 36 | set -g status-right '#[fg=green,bg=default,bright]#(tmux-mem-cpu-load) #[fg=red,dim,bg=default]#(uptime | cut -f 4-5 -d " " | cut -f 1 -d ",") #[fg=white,bg=default]%a%l:%M:%S %p#[default] #[fg=blue]%Y-%m-%d' 37 | 38 | # C-b is not acceptable -- Vim uses it 39 | set-option -g prefix C-a 40 | bind-key C-a last-window 41 | 42 | # Start numbering at 1 43 | set -g base-index 1 44 | 45 | # Allows for faster key repetition 46 | set -s escape-time 50 47 | 48 | # Rather than constraining window size to the maximum size of any client 49 | # connected to the *session*, constrain window size to the maximum size of any 50 | # client connected to *that window*. Much more reasonable. 51 | setw -g aggressive-resize on 52 | 53 | # Allows us to use C-a a to send commands to a TMUX session inside 54 | # another TMUX session 55 | bind-key a send-prefix 56 | 57 | # Activity monitoring 58 | setw -g monitor-activity on 59 | set -g visual-activity on 60 | 61 | # hjkl pane traversal 62 | bind h select-pane -L 63 | bind j select-pane -D 64 | bind k select-pane -U 65 | bind l select-pane -R 66 | 67 | # set to main-horizontal, 66% height for main pane 68 | bind m run-shell "~/.tmux/scripts/resize-adaptable.sh -l main-horizontal -p 66" 69 | # Same thing for verical layouts 70 | bind M run-shell "~/.tmux/scripts/resize-adaptable.sh -l main-vertical -p 50" 71 | 72 | bind-key C command-prompt -p "Name of new window: " "new-window -n '%%'" 73 | 74 | # reload config 75 | bind r source-file ~/.tmux.conf \; display-message "Config reloaded..." 76 | 77 | # auto window rename 78 | set-window-option -g automatic-rename 79 | 80 | # https://github.com/edkolev/dots/blob/master/tmux.conf 81 | # Updates for tmux 1.9's current pane splitting paths. 82 | 83 | # from powerline 84 | run-shell "tmux set-environment -g TMUX_VERSION_MAJOR $(tmux -V | cut -d' ' -f2 | cut -d'.' -f1 | sed 's/[^0-9]*//g')" 85 | run-shell "tmux set-environment -g TMUX_VERSION_MINOR $(tmux -V | cut -d' ' -f2 | cut -d'.' -f2 | sed 's/[^0-9]*//g')" 86 | 87 | # Vi copypaste mode 88 | set-window-option -g mode-keys vi 89 | if-shell "test '\( #{$TMUX_VERSION_MAJOR} -eq 2 -a #{$TMUX_VERSION_MINOR} -ge 4 \)'" 'bind-key -Tcopy-mode-vi v send -X begin-selection; bind-key -Tcopy-mode-vi y send -X copy-selection-and-cancel' 90 | if-shell '\( #{$TMUX_VERSION_MAJOR} -eq 2 -a #{$TMUX_VERSION_MINOR} -lt 4\) -o #{$TMUX_VERSION_MAJOR} -le 1' 'bind-key -t vi-copy v begin-selection; bind-key -t vi-copy y copy-selection' 91 | 92 | # status bar 93 | if-shell '\( #{$TMUX_VERSION_MAJOR} -eq 2 -a #{$TMUX_VERSION_MINOR} -lt 2\) -o #{$TMUX_VERSION_MAJOR} -le 1' 'set-option -g status-utf8 on' 94 | 95 | # rm mouse mode fail 96 | if-shell '\( #{$TMUX_VERSION_MAJOR} -eq 2 -a #{$TMUX_VERSION_MINOR} -ge 1\)' 'set -g mouse off' 97 | if-shell '\( #{$TMUX_VERSION_MAJOR} -eq 2 -a #{$TMUX_VERSION_MINOR} -lt 1\) -o #{$TMUX_VERSION_MAJOR} -le 1' 'set -g mode-mouse off' 98 | 99 | # fix pane_current_path on new window and splits 100 | if-shell "test '#{$TMUX_VERSION_MAJOR} -gt 1 -o \( #{$TMUX_VERSION_MAJOR} -eq 1 -a #{$TMUX_VERSION_MINOR} -ge 8 \)'" 'unbind c; bind c new-window -c "#{pane_current_path}"' 101 | if-shell "test '#{$TMUX_VERSION_MAJOR} -gt 1 -o \( #{$TMUX_VERSION_MAJOR} -eq 1 -a #{$TMUX_VERSION_MINOR} -ge 8 \)'" "unbind '\"'; bind '\"' split-window -v -c '#{pane_current_path}'" 102 | if-shell "test '#{$TMUX_VERSION_MAJOR} -gt 1 -o \( #{$TMUX_VERSION_MAJOR} -eq 1 -a #{$TMUX_VERSION_MINOR} -ge 8 \)'" 'unbind v; bind v split-window -h -c "#{pane_current_path}"' 103 | if-shell "test '#{$TMUX_VERSION_MAJOR} -gt 1 -o \( #{$TMUX_VERSION_MAJOR} -eq 1 -a #{$TMUX_VERSION_MINOR} -ge 8 \)'" 'unbind "%"; bind % split-window -h -c "#{pane_current_path}"' 104 | 105 | 106 | # Colors 107 | # How to use true colors in vim under tmux? #1246 for 2.6 and higher 108 | # https://github.com/tmux/tmux/issues/1246: 109 | # set -g default-terminal "tmux-256color" 110 | # set -ga terminal-overrides ",*256col*:Tc" 111 | # 2.5 and lower: 112 | # set -g default-terminal "xterm-256color" 113 | 114 | # Doesn't work on iterm2 / mac 115 | # if-shell "test '\( #{$TMUX_VERSION_MAJOR} -eq 2 -a #{$TMUX_VERSION_MINOR} -ge 6 \)'" 'set -g default-terminal "tmux-256color"' 116 | # if-shell "test '\( #{$TMUX_VERSION_MAJOR} -eq 2 -a #{$TMUX_VERSION_MINOR} -ge 6 \)'" 'set -ga terminal-overrides ",*256col*:Tc"' 117 | 118 | # Try xterm256-color (https://github.com/tmux/tmux/issues/622): 119 | if-shell "test '\( #{$TMUX_VERSION_MAJOR} -eq 2 -a #{$TMUX_VERSION_MINOR} -ge 6 \)'" 'set -g default-terminal "xterm-256color"' 120 | if-shell "test '\( #{$TMUX_VERSION_MAJOR} -eq 2 -a #{$TMUX_VERSION_MINOR} -ge 6 \)'" 'set -ga terminal-overrides ",xterm-256color:Tc"' 121 | 122 | if-shell '\( #{$TMUX_VERSION_MAJOR} -eq 2 -a #{$TMUX_VERSION_MINOR} -lt 6\) -o #{$TMUX_VERSION_MAJOR} -le 1' 'set -g default-terminal "xterm-256color"' 123 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [tmux](http://tmux.sourceforge.net/) is a terminal multiplexer. 2 | 3 | - Tested with tmux 1.5+. 4 | - Support for [tmux-mem-cpu-load](http://github.com/thewtex/tmux-mem-cpu-load). 5 | - Prefix mapped to Ctrl-A for `screen` users. 6 | 7 | New to tmux? [_The Tao of tmux_](https://leanpub.com/the-tao-of-tmux) is now available on Leanpub 8 | and [Amazon Kindle](http://amzn.to/2gPfRhC). Read and browse the book for 9 | [on the web](https://leanpub.com/the-tao-of-tmux/read). 10 | 11 | Want more tmux? Check out the [libtmux](https://github.com/tony/libtmux) python library for 12 | controlling tmux, and load your code projects via YAML/JSON with 13 | [tmuxp](https://github.com/tony/tmuxp). 14 | 15 | ## Share your .dot-configs 16 | 17 | Have a tmux configuration you'd like to share? Whether a fork of this project, another's, or your 18 | own, submit it to [awesome-tmux-configs](https://github.com/tony/awesome-tmux-configs). 19 | 20 | ## Installation 21 | 22 | Download: 23 | 24 | ```bash 25 | git clone --recursive https://github.com/tony/tmux-config.git ~/.tmux 26 | ``` 27 | 28 | Copy tmux config to home: 29 | 30 | ```bash 31 | ln -s ~/.tmux/.tmux.conf ~/.tmux.conf 32 | ``` 33 | 34 | Go to config dir: 35 | 36 | ```bash 37 | cd ~/.tmux 38 | ``` 39 | 40 | ## Stats 41 | 42 | ### tmux-mem-cpu-load 43 | 44 | Works on Linux and OS X. 45 | 46 | Prep ourself to download submodule (if you forgot `--recursive` when cloning): 47 | 48 | ```bash 49 | git submodule init 50 | ``` 51 | 52 | Download submodule: 53 | 54 | ```bash 55 | git submodule update 56 | ``` 57 | 58 | Change dir to tmux-mem-cpu-load: 59 | 60 | ```bash 61 | cd ~/.tmux/vendor/tmux-mem-cpu-load 62 | ``` 63 | 64 | Make `_build` directory and `cd` into it: 65 | 66 | ```bash 67 | mkdir _build; cd _build 68 | ``` 69 | 70 | General make file: 71 | 72 | ```bash 73 | cmake .. 74 | ``` 75 | 76 | Compile binary: 77 | 78 | ```bash 79 | make 80 | ``` 81 | 82 | Install our binary to `/usr/local/bin/tmux-mem-cpu-load`: 83 | 84 | ```bash 85 | sudo make install 86 | ``` 87 | 88 | (No need to do `sudo` if on OS X / macOS) 89 | 90 | Go home: 91 | 92 | ```bash 93 | cd ~ 94 | ``` 95 | 96 | Launch tmux: 97 | 98 | ``` 99 | tmux 100 | ``` 101 | 102 | And press `Control + a` then `d` to go back to the terminal. 103 | 104 | Update config: 105 | 106 | ```bash 107 | tmux source-file ~/.tmux.conf 108 | ``` 109 | 110 | ### basic-cpu-and-memory.tmux 111 | 112 | (Cross platform, tested with python 2.7+) 113 | 114 | Update March 19, 2014. Works with psutil 2.0 now. 115 | 116 | Install `psutil`: 117 | 118 | ```bash 119 | sudo pip install psutil 120 | ``` 121 | 122 | Copy `~/.tmux/vendor/basic-cpu-and-memory.tmux` to bin: 123 | 124 | ```bash 125 | sudo cp ~/.tmux/vendor/basic-cpu-and-memory.tmux /usr/local/bin/tmux-mem-cpu-load 126 | ``` 127 | 128 | make executable: 129 | 130 | ```bash 131 | sudo chmod +x /usr/local/bin/tmux-mem-cpu-load 132 | ``` 133 | 134 | ### Powerline (Advanced) 135 | 136 | You can add suport for [powerline](https://github.com/powerline/powerline) by adding these to your 137 | `~/.tmux.conf`. Be sure to grab and install [powerline-fonts](https://github.com/powerline/fonts) 138 | for your system. 139 | 140 | See [Powerline on ReadTheDocs.org](https://powerline.readthedocs.org/en/master/) for more info. 141 | 142 | ``` 143 | # pip install --user git+git://github.com/powerline/powerline 144 | if-shell 'test -f ~/.local/lib/python2.7/site-packages/powerline/bindings/tmux/powerline.conf' 'source-file ~/.local/lib/python2.7/site-packages/powerline/bindings/tmux/powerline.conf' 145 | 146 | # [sudo] pip install git+git://github.com/powerline/powerline 147 | if-shell 'test -f /usr/local/lib/python2.7/site-packages/powerline/bindings/tmux/powerline.conf' 'source-file /usr/local/lib/python2.7/site-packages/powerline/bindings/tmux/powerline.conf' 148 | 149 | # [sudo] pip install git+git://github.com/powerline/powerline 150 | if-shell 'test -f /usr/local/lib/python2.7/dist-packages/powerline/bindings/tmux/powerline.conf' 'source-file /usr/local/lib/python2.7/dist-packages/powerline/bindings/tmux/powerline.conf' 151 | # python 3.3 ? 152 | if-shell 'test -f /usr/local/lib/python3.3/dist-packages/powerline/bindings/tmux/powerline.conf' 'source-file /usr/local/lib/python3.3/dist-packages/powerline/bindings/tmux/powerline.conf' 153 | # python 3.4 ? 154 | # if-shell 'test -f /usr/local/lib/python3.4/dist-packages/powerline/bindings/tmux/powerline.conf' 'source-file /usr/local/lib/python3.4/dist-packages/powerline/bindings/tmux/powerline.conf' 155 | # python 3.5 ? 156 | # if-shell 'test -f /usr/local/lib/python3.5/dist-packages/powerline/bindings/tmux/powerline.conf' 'source-file /usr/local/lib/python3.5/dist-packages/powerline/bindings/tmux/powerline.conf' 157 | # python 3.6 ? 158 | # if-shell 'test -f /usr/local/lib/python3.6/dist-packages/powerline/bindings/tmux/powerline.conf' 'source-file /usr/local/lib/python3.6/dist-packages/powerline/bindings/tmux/powerline.conf' 159 | ``` 160 | 161 | ## Start tmux 162 | 163 | To start a session: 164 | 165 | `tmux` 166 | 167 | To reattach a previous session: 168 | 169 | `tmux attach` 170 | 171 | To reload config file 172 | 173 | `:` (which could Ctrl-B or Ctrl-A if you overidden it) then `source-file ~/.tmux.conf` 174 | 175 | ## Commands 176 | 177 | Our prefix/leader key is `Control + a` now (just like the `screen` multiplexer). This sequence must 178 | be typed before any tmux shortcut. 179 | 180 | - `Control + a` before any command 181 | - `Control + a` then `?` to bring up list of keyboard shortcuts 182 | - `Control + a` then `"` to split window 183 | - `Control + a` then `` to change pane arrangement 184 | - `Control + a` then `o` to rotate panes 185 | - `Control + a` then `h`, `j`, `k`, `l` to move left, down, up, right. Respectively. (vim hjkl) 186 | - `Control + a` then `;` to go to last panel 187 | 188 | Beyond your first window: 189 | 190 | - `Control + a` then `c` to create a new window 191 | - `Control + a` then `n` to next window 192 | - `Control + a` then `p` to previous window 193 | - `Control + a` then `[0-9]` move to window number 194 | - `Control + a` then `&` to kill window 195 | 196 | Custom: 197 | 198 | - `Control + a` then `m` to switch to `main-horizontal` layout with the main window at 2/3 height.. 199 | - `Control + a` then `M` to switch to `main-vertical` layout with the main window at half width. 200 | 201 | ## More configs / Tools 202 | 203 | - _Save / Load your tmux workspaces through JSON or YAML_ with 204 | [tmuxp](https://github.com/tony/tmuxp). 205 | - _Clone + Synchronize your git / hg / svn projects through JSON / YAML_ with 206 | [vcspull](https://github.com/tony/vcspull). 207 | - _Modular, Lazy-loading vim configuration_ with support for C, C++, Python, Go and Javascript with 208 | [tony/vim-config](https://github.com/tony/vim-config) 209 | - _Modular dot-config example_ [tony/.dot-config](https://github.com/tony/.dot-config) 210 | 211 | ## Other 212 | 213 | - Github: http://www.github.com/tony 214 | - Website: http://www.git-pull.com 215 | - LICENSE: MIT 216 | - Author: Tony Narlock (tony@git-pull.com) 217 | -------------------------------------------------------------------------------- /install.sh: -------------------------------------------------------------------------------- 1 | # Author arthurkiller 2 | # email arthur-lee@qq.com 3 | # data 2017-1-4 4 | # this shell is used for initialize the tmux-config 5 | 6 | #!/bin/bash 7 | 8 | trap exit ERR 9 | if [ -d $HOME/.tmux ] 10 | then 11 | echo .tmux already exist 12 | mv $HOME/.tmux $HOME/.tmux.bak 13 | fi 14 | 15 | if [ -e $HOME/.tmux.conf ] 16 | then 17 | echo .tmux.conf already exist 18 | mv $HOME/.tmux.conf $HOME/.tmux.conf.bak 19 | fi 20 | 21 | cp -r $HOME/tmux-config $HOME/.tmux 22 | ln -s $HOME/.tmux/.tmux.conf $HOME/.tmux.conf 23 | 24 | cd ~/.tmux && git submodule init && git submodule update 25 | 26 | cd ~/.tmux/vendor/tmux-mem-cpu-load && cmake . && make && sudo make install 27 | 28 | tmux source-file ~/.tmux.conf 29 | -------------------------------------------------------------------------------- /scripts/resize-adaptable.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Adaptable tmux resize script by percentage 3 | # 4 | # Layout types supported (-l): 5 | # 6 | # main-horizontal: top pane is main pane, panes split left to right on the bottom 7 | # main-vertical: left pane is maine pane, right panes split top to bottom on the 8 | # right side 9 | # 10 | # Options: 11 | # 12 | # -l layout-name (required): the name of the layout, "main-horizontal" or "main-vertical" 13 | # -p percentage (required): an integer of the percentage of the client width/height to set 14 | # -t target-window (optional): the tmux target for the window, can be an fnmatch(1) of the 15 | # window name, index, or id 16 | # 17 | # Example usage: 18 | # 19 | # Case 1: Resize to a main-horizontal, main pane 66% of client height 20 | # $ ./scripts/resize-adaptable.sh -p 66 -l main-horizontal 21 | # 22 | # Case 2: Same as Case 1, target "devel" window 23 | # $ ./scripts/resize-adaptable.sh -p 66 -l main-horizontal -t devel 24 | # 25 | # Case 3: Resize to a main-horizontal, main pane half width 26 | # $ ./scripts/resize-adaptable.sh -p 50 -l main-vertical 27 | # 28 | # Case 4: Same as Case 3, target "mywindow" 29 | # $ ./scripts/resize-adaptable.sh -p 50 -l main-vertical -t mywindow 30 | # 31 | # Author: Tony Narlock 32 | # Website: https://devel.tech 33 | # License: MIT 34 | 35 | lflag= 36 | pflag= 37 | tflag= 38 | while getopts l:p:t: name; 39 | do 40 | case $name in 41 | l) lflag=1 42 | layout_name=$OPTARG;; 43 | p) pflag=1 44 | percentage="$OPTARG";; 45 | t) tflag=1 46 | target="$OPTARG";; 47 | ?) printf "Usage: %s: [-l layout-name] [-p percentage] [-t target-window]\n" $0 48 | exit 2;; 49 | esac 50 | done 51 | 52 | if [ ! -z "$pflag" ]; then 53 | if ! [ "$percentage" -eq "$percentage" ] 2> /dev/null; then 54 | printf "Percentage (-p) must be an integer" >&2 55 | exit 1 56 | fi 57 | fi 58 | if [ ! -z "$lflag" ]; then 59 | if [ $layout_name != 'main-horizontal' ] && [ $layout_name != 'main-vertical' ] ; then 60 | printf "layout name must be main-horizontal or main-vertical" >&2 61 | exit 1 62 | fi 63 | fi 64 | 65 | if [ "$layout_name" = "main-vertical" ]; then 66 | MAIN_PANE_SIZE=$(expr $(tmux display -p '#{window_width}') \* $percentage \/ 100) 67 | MAIN_SIZE_OPTION='main-pane-width' 68 | 69 | fi 70 | 71 | if [ "$layout_name" = "main-horizontal" ]; then 72 | MAIN_PANE_SIZE=$(expr $(tmux display -p '#{window_height}') \* $percentage \/ 100) 73 | MAIN_SIZE_OPTION='main-pane-height' 74 | fi 75 | 76 | if [ ! -z "$target" ]; then 77 | tmux setw -t $target $MAIN_SIZE_OPTION $MAIN_PANE_SIZE; tmux select-layout -t $target $layout_name 78 | else 79 | tmux setw $MAIN_SIZE_OPTION $MAIN_PANE_SIZE; tmux select-layout $layout_name 80 | fi 81 | 82 | exit 0 83 | -------------------------------------------------------------------------------- /vendor/basic-cpu-and-memory.tmux: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """ 4 | Basic CPU & Memory Usage for Tmux 5 | 6 | Author: Zaiste! 7 | 8 | Dash-meter inspired by tmux-mem-cpu 9 | and code from psutil top.py. 10 | 11 | From https://github.com/zaiste/tmuxified 12 | 13 | Changes by Tony Narlock at 14 | https://github.com/tony/tmux-config. 15 | """ 16 | 17 | import os 18 | import sys 19 | if os.name != 'posix': 20 | sys.exit('platform not supported') 21 | import psutil 22 | 23 | 24 | def get_dashes(perc): 25 | dashes = "|" * int((float(perc) / 10)) 26 | empty_dashes = " " * (10 - len(dashes)) 27 | return dashes, empty_dashes 28 | 29 | 30 | def info(): 31 | mem = psutil.virtual_memory() 32 | if hasattr(mem, 'cached'): 33 | memused = mem.used - mem.cached 34 | else: 35 | memused = mem.used 36 | 37 | cpu_dashes, cpu_empty_dashes = get_dashes(psutil.cpu_percent(interval=0.1)) 38 | line = "%s/%sMB [%s%s] %5s%%" % ( 39 | str(int(memused / 1024 / 1024)), 40 | str(int(mem.total / 1024 / 1024)), 41 | cpu_dashes, cpu_empty_dashes, 42 | psutil.cpu_percent(interval=0.1), 43 | ) 44 | 45 | return line 46 | 47 | 48 | def main(): 49 | try: 50 | print info() 51 | except (KeyboardInterrupt, SystemExit): 52 | pass 53 | 54 | if __name__ == '__main__': 55 | main() 56 | --------------------------------------------------------------------------------