Created
January 7, 2019 12:22
-
-
Save weaming/e59326453df9f5c1361575e516212545 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# coding: utf-8 | |
""" | |
Author : weaming | |
Created Time : 2019-01-07 17:10:31 | |
pip3 install requests jsonkv | |
""" | |
import os | |
import time | |
import argparse | |
import requests | |
from jsonkv import JsonKV | |
API = "http://ip-api.com/json" | |
config = os.path.expanduser("~/.config/geoip.json") | |
update_hours = 3 | |
def prepare_dir(path): | |
if not path.endswith("/"): | |
path = os.path.dirname(path) | |
if not os.path.isdir(path): | |
os.makedirs(path) | |
def prepare_db(): | |
if not os.path.isfile(config): | |
prepare_dir(config) | |
with open(config, "w"): | |
pass | |
def get_data(): | |
with JsonKV(config) as db: | |
ts = db["ts"] | |
if not ts or time.time() - ts > 60 * 60 * update_hours: | |
data = requests.get(API).json() | |
db["ts"] = time.time() | |
db["geoip"] = data | |
else: | |
data = db["geoip"] | |
return data | |
def parse_args(): | |
parser = argparse.ArgumentParser() | |
parser.add_argument( | |
"key", nargs="+", help="the keys of data from http://ip-api.com/json" | |
) | |
parser.add_argument("--sep", default="\n", help="separator of values") | |
args = parser.parse_args() | |
return args | |
def main(): | |
args = parse_args() | |
prepare_db() | |
data = get_data() | |
values = [data[k] for k in args.key] | |
print(args.sep.join(values)) | |
if __name__ == "__main__": | |
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# remap prefix from 'C-b' to 'C-a' | |
unbind C-b | |
set-option -g prefix C-a | |
bind-key C-a send-prefix | |
set -g base-index 1 # start windows numbering at 1 | |
setw -g pane-base-index 1 # make pane numbering consistent with windows | |
# Automatically set window title | |
set-window-option -g automatic-rename on | |
set-option -g set-titles on | |
set -g default-terminal screen-256color | |
set -g status-keys vi | |
set -g history-limit 100000 | |
set -g mode-keys vi | |
# set -g mouse on | |
set -g monitor-activity on | |
# Sane Split Commands | |
bind | split-window -h -c '#{pane_current_path}' | |
bind - split-window -v -c '#{pane_current_path}' | |
# Resize pannes | |
bind-key J resize-pane -D 5 | |
bind-key K resize-pane -U 5 | |
bind-key H resize-pane -L 5 | |
bind-key L resize-pane -R 5 | |
# Use Alt-arrow keys without prefix key to resize panes | |
bind -n M-Left resize-pane -L 5 | |
bind -n M-Down resize-pane -D 5 | |
bind -n M-Up resize-pane -U 5 | |
bind -n M-Right resize-pane -R 5 | |
# Switch Panes: | |
# Vim style pane selection | |
bind h select-pane -L | |
bind j select-pane -D | |
bind k select-pane -U | |
bind l select-pane -R | |
# Use Alt-arrow keys without prefix key to switch panes | |
bind -n M-h select-pane -L | |
bind -n M-l select-pane -R | |
bind -n M-k select-pane -U | |
bind -n M-j select-pane -D | |
# Shift arrow to switch windows | |
bind -n S-Left previous-window | |
bind -n S-Right next-window | |
# No delay for escape key press | |
set -sg escape-time 0 | |
# Reload tmux config | |
bind r source-file ~/.tmux.conf | |
# THEME | |
set -g status-bg black | |
set -g status-fg white | |
set -g window-status-current-bg white | |
set -g window-status-current-fg black | |
set -g window-status-current-attr bold | |
set -g status-interval 1 | |
set -g status-left-length 100 | |
set -g status-right-length 100 | |
set -g status-left "#[fg=yellow] #(whoami) #[fg=green]#(ifconfig | grep inet | grep -v inet6 | grep -v 127 | awk '{print $2}') " | |
set -g status-right '#[default] #[fg=green]#(geoip.py query) #[fg=#005b96]#(geoip.py city regionName countryCode isp --sep " | ") #[fg=#be29ec]%Y-%m-%d %H:%M:%S#[default]' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment