diff --git a/VERSION b/VERSION index e516bb9..c514bd8 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.4.5 +1.4.6 diff --git a/bin/base/date b/bin/base/date new file mode 100755 index 0000000..51d7f22 --- /dev/null +++ b/bin/base/date @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +echo $(date '+%Y-%m-%d') diff --git a/bin/base/datetime b/bin/base/datetime new file mode 100755 index 0000000..02719fb --- /dev/null +++ b/bin/base/datetime @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +echo $(date '+%Y-%m-%d %H:%M:%S') diff --git a/bin/base/size b/bin/base/size new file mode 100755 index 0000000..1329677 --- /dev/null +++ b/bin/base/size @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + + diff --git a/bin/base/size.py b/bin/base/size.py new file mode 100755 index 0000000..ee22d49 --- /dev/null +++ b/bin/base/size.py @@ -0,0 +1,105 @@ +#!/usr/bin/env python +# -*- coding:utf-8 -*- +# Author: wxnacy(wxnacy@gmail.com) +# Description: + +import os + + +def get_size(path): + '''获取文件的大小''' + def _size(p, s: int): + if os.path.isfile(p): + s += os.path.getsize(p) + # print(s, os.path.getsize(p), p) + else: + files = os.listdir(p) + for f in files: + fp = '{}/{}'.format(p, f) + s = _size(fp, s) + return s + res = _size(path, 0) + # print(res) + return res + +def get_size1(path): + '''获取文件的大小''' + if os.path.isfile(path): + return os.path.getsize(path) + + size = 0 + for root, dirs, filenames in os.walk(path): + for filename in filenames: + filepath = '{}/{}'.format(root, filename) + size += os.path.getsize(filepath) + return size + +def format_size(size: int): + '''格式化大小''' + + unit = { + 0: 'B', + 1: 'K', + 2: 'M', + 3: 'T', + 4: 'P', + } + + for i in range(1, 6): + max_size = 1024 ** i + if size < max_size: + j = i - 1 + if j < 1: + res = size + else: + res = size / 1028 * j + return '{:0.1f}{}'.format( res, unit[j]) + +class File(): + def __init__(self, path, *args, **kwargs): + self.path = path + +if __name__ == "__main__": + import sys + args = sys.argv[1:] + path = '.' + is_fmt = False + for a in args: + if not a.startswith('-') and a: + path = a + if a == '-h': + is_fmt = True + + # if len(args) >=1: + # path = args[0] + + # print(path) + + lists = [] + + total_size = 0 + if os.path.isfile(path): + print(os.path.getsize(path)) + sys.exit(0) + files = os.listdir(path) + for f in files: + filepath = '{}/{}'.format(path, f) + size = get_size(filepath) + total_size += size + fmt_size = format_size(size) if is_fmt else size + line = '{}\t\t{}'.format(fmt_size, f) + print(line) + lists.append(dict(size= size, name = f)) + fmt_total = format_size(total_size) if is_fmt else total_size + print('Total:', fmt_total) + print('开始排序') + + lists.sort(key = lambda o: o['size'], reverse=True) + for l in lists[0:10]: + size = l['size'] + f = l['name'] + fmt_size = format_size(size) if is_fmt else size + line = '{}\t\t{}'.format(fmt_size, f) + print(line) + + diff --git a/bin/base/split b/bin/base/split new file mode 100755 index 0000000..3cf9c3b --- /dev/null +++ b/bin/base/split @@ -0,0 +1,22 @@ +#!/usr/bin/env bash + +echo $@ +echo 'split' + +file=$1 +sep=$2 + +if [ $sep == "-d" ] +then + echo 's' + d=`date '+%Y-%m-%d'` + echo $d + # echo $(awk '/$d 00/ {print $0}' $file) + cmd="awk '" + cmd=${cmd}"/$d/ {print \$0}" + cmd=${cmd}"' $file" + echo $cmd + `$cmd` +fi + + diff --git a/bin/base/split.awk b/bin/base/split.awk new file mode 100755 index 0000000..df5f9dd --- /dev/null +++ b/bin/base/split.awk @@ -0,0 +1,22 @@ +#!/usr/bin/env awk -f + +echo $@ +echo 'split' + +file=$1 +sep=$2 + +if [ $sep == "-d" ] +then + echo 's' + d=`date '+%Y-%m-%d'` + echo $d + # echo $(awk '/$d 00/ {print $0}' $file) + cmd="awk '" + cmd=${cmd}"/$d/ {print \$0}" + cmd=${cmd}"' $file" + echo $cmd + `$cmd` +fi + + diff --git a/bin/base/test_size.py b/bin/base/test_size.py new file mode 100644 index 0000000..9ea33c6 --- /dev/null +++ b/bin/base/test_size.py @@ -0,0 +1,55 @@ +#!/usr/bin/env python +# -*- coding:utf-8 -*- +# Author: wxnacy(wxnacy@gmail.com) +# Description: + +import unittest +import timeit +from size import get_size +from size import get_size1 +from size import format_size + +class TestMain(unittest.TestCase): + + def setUp(self): + '''before each test function''' + pass + + def tearDown(self): + '''after each test function''' + pass + + def do(self, func): + '''todo''' + self.assertEqual(1, 1) + pass + + def test_func(self): + # self.do() + path = '/Users/wxnacy/Documents' + self.assertEqual(get_size(path), get_size1(path)) + + self.assertEqual + + def test_format_size(self): + self.assertEqual(format_size(234), '234.0B') + self.assertEqual(format_size(1234), '1.2K') + +def speed(count, func, *args): + b = timeit.default_timer() + for i in range(count): + func(*args) + print('{} run {} times used: {}s'.format( + func.__name__.ljust(20), count, + timeit.default_timer() - b + )) + + +if __name__ == "__main__": + count = 15 + path = '/Users/wxnacy/Documents' + speed(count, get_size, path) + speed(count, get_size1, path) + + + unittest.main() diff --git a/bin/base/time b/bin/base/time new file mode 100755 index 0000000..a1fa099 --- /dev/null +++ b/bin/base/time @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +echo $(date '+%H:%M:%S') diff --git a/bin/pyenv/install b/bin/pyenv/install index 65ea2f3..21ded2c 100755 --- a/bin/pyenv/install +++ b/bin/pyenv/install @@ -6,25 +6,35 @@ SYS=${OSS[0]} VER=${OSS[1]} PKG=${OSS[2]} -case $SYS in - debian|ubuntu|devuan|deepin) - sudo apt update -y - sudo apt -y install git gcc make patch zlib1g.dev libgdbm-dev libssl-dev libsqlite3-dev libbz2-dev libreadline-dev - curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash - ;; - centos|fedora|rhel|amzn) - sudo yum update -y - sudo yum -y install git gcc readline readline-devel readline-static openssl openssl-devel openssl-static sqlite-devel bzip2-devel bzip2-libs - curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash - ;; - Darwin) - brew update - brew install pyenv - ;; - *) - echo '暂时不支持该系统' - ;; -esac +pyver=$1 + +install_pyenv(){ + path=`command -v pyenv` + if [ $path ];then + echo -e "pyenv is install on $path" + exit + fi + + case $SYS in + debian|ubuntu|devuan|deepin) + sudo apt update -y + sudo apt -y install git gcc make patch zlib1g.dev libgdbm-dev libssl-dev libsqlite3-dev libbz2-dev libreadline-dev + curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash + ;; + centos|fedora|rhel|amzn) + sudo yum update -y + sudo yum -y install git gcc readline readline-devel readline-static openssl openssl-devel openssl-static sqlite-devel bzip2-devel bzip2-libs + curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash + ;; + Darwin) + brew update + brew install pyenv + ;; + *) + echo '暂时不支持该系统' + ;; + esac +} # BP=~/.bash_profile # if [ -f ~/.profile ];then @@ -42,3 +52,14 @@ esac # # nohup pyenv install 2.7.12 & # # nohup pyenv install 3.6.0 & # fi + +if [ ! ${pyver} ] +then + install_pyenv +else + # url=https://www.python.org/ftp/python/${pyver}/Python-${pyver}.tar.xz + url=https://github.com/wxnacy/file/releases/download/python/Python-${pyver}.tar.xz + wget ${url} -P ~/.pyenv/cache/ + pyenv install ${pyver} + # wget http://mirrors.sohu.com/python/${python_version}/Python-${python_version}.tar.xz \ +fi diff --git a/conf/bash/bash_aliases b/conf/bash/bash_aliases index 19c5433..6e1de3f 100644 --- a/conf/bash/bash_aliases +++ b/conf/bash/bash_aliases @@ -40,3 +40,6 @@ alias vgd="vagrant destroy -f" # autossh alias assh="autossh -M 0 " +# python +alias pipi="pip install -i https://pypi.tuna.tsinghua.edu.cn/simple" +alias pydb="python -m pdb" diff --git a/conf/bash/bashrc b/conf/bash/bashrc index a78bc02..d730314 100644 --- a/conf/bash/bashrc +++ b/conf/bash/bashrc @@ -10,9 +10,6 @@ export PATH=$PATH:/Users/wxnacy/PycharmProjects/study/goland/bin export WS_HOME="${HOME}/.wshell" export PATH=$PATH:${WS_HOME}/bin -# for image -export PATH=$PATH:/Users/wxnacy/Projects/image - function proxyoff(){ unset http_proxy diff --git a/conf/zsh/zprofile b/conf/zsh/zprofile index 3a4c3c7..514820d 100644 --- a/conf/zsh/zprofile +++ b/conf/zsh/zprofile @@ -17,3 +17,9 @@ if [ -d "${HOME}/.nvm" ]; then [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion fi + +# for python +# source /usr/local/opt/autoenv/activate.sh + +# CFLAGS="-I$(brew --prefix openssl)/include" \ +# LDFLAGS="-L$(brew --prefix openssl)/lib" diff --git a/conf/zsh/zshrc b/conf/zsh/zshrc index bd50b49..c09c981 100644 --- a/conf/zsh/zshrc +++ b/conf/zsh/zshrc @@ -8,8 +8,9 @@ export ZSH=${HOME}/.oh-my-zsh # https://github.com/robbyrussell/oh-my-zsh/wiki/themes # ZSH_THEME="fishy" ZSH_THEME="bureau" +# ZSH_THEME="spaceship" # source ${HOME}/.oh-my-zsh/themes/bureau.zsh-theme - +# fpath=( "$HOME/.zfunctions" $fpath ) plugins=(git python sublime) source $ZSH/oh-my-zsh.sh @@ -19,3 +20,6 @@ source $ZSH/oh-my-zsh.sh if [ -f ~/.bashrc ]; then source ~/.bashrc fi +# autoload -U promptinit; promptinit + +# prompt spaceship diff --git a/test/test/b.sh b/test/test/b.sh new file mode 100755 index 0000000..956c70d --- /dev/null +++ b/test/test/b.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + + +# source a.sh +. a.sh +echo $name diff --git a/wshell-installer b/wshell-installer index b0cd63a..bf9d19c 100755 --- a/wshell-installer +++ b/wshell-installer @@ -30,7 +30,7 @@ if [[ ! $PATH =~ '.wshell/bin' ]];then echo \' '>> ~/.bashrc' echo -n -e "\t"echo \' - echo -n '. ${WS_HOME}/conf/system/bashrc' + echo -n '. ${WS_HOME}/conf/bash/bashrc' echo \' '>> ~/.bashrc' echo -e "\tsource ~/.bashrc"