• mac控制台命令小技巧


    shigen日更文章的博客写手,擅长Java、python、vue、shell等编程语言和各种应用程序、脚本的开发。记录成长,分享认知,留住感动。

    hello伙伴们,作为忠实的mac骨灰级别的粉丝,它真的给我带来了很多效率上的提升。那作为接触的最多的软件之一——终端,其实shigen每天80%的时间都在终端上倒腾的,运行我的各种脚本工具。那效率肯定得提上上去了,shigen的电脑终端就很丝滑。

    首先,答应我;不要再使用系统的终端了,使用 iterm2吧,它的功能很强大,而且支持很多自定义的配置。

    shigen的iterm2

    当然,为了酷炫,实际的并没有这么的花哨。

    好了工具有了,那怎么提升效率呢?今天的分享主要是alias有关,也是shigen在实习的时候,跟着我的运维伙伴学到的。

    我的alias

    alias mci="mvn clean install"
    
    # some alias
    alias g=git
    alias ga='git add'
    alias gaa='git add --all'
    alias gap='git add --patch'
    alias gb='git branch'
    alias gba='git branch -a'
    alias gbr='git branch --remote'
    alias gc='git commit -v'
    alias gca='git commit -v -a'
    alias gcl='git config --list'
    alias gclean='git reset --hard && git clean -dfx'
    alias gcm='git checkout master'
    alias gcmsg='git commit -m'
    alias gco='git checkout'
    alias gcount='git shortlog -sn'
    alias gcp='git cherry-pick'
    alias gcs='git commit -S'
    alias gd='git diff'
    alias gdc='git diff --cached'
    alias gdt='git difftool'
    alias gg='git gui citool'
    alias gga='git gui citool --amend'
    alias ggpnp='git pull origin $(current_branch) && git push origin $(current_branch)'
    alias ggpull='git pull origin $(current_branch)'
    alias ggpur='git pull --rebase origin $(current_branch)'
    alias ggpush='git push origin $(current_branch)'
    alias gignore='git update-index --assume-unchanged'
    alias gignored='git ls-files -v | grep "^[[:lower:]]"'
    alias gk='gitk --all --branches'
    alias gl='git pull'
    alias glg='git log --stat --max-count=10'
    alias glgg='git log --graph --max-count=10'
    alias glgga='git log --graph --decorate --all'
    alias glo='git log --oneline --decorate --color'
    alias globurl='noglob urlglobber '
    alias glog='git log --oneline --decorate --color --graph'
    alias glp=_git_log_prettily
    alias gm='git merge'
    alias gmt='git mergetool --no-prompt'
    alias gp='git push'
    alias gpoat='git push origin --all && git push origin --tags'
    alias gr='git remote'
    alias grba='git rebase --abort'
    alias grbc='git rebase --continue'
    alias grbi='git rebase -i'
    alias grep='grep  --color=auto --exclude-dir={.bzr,.cvs,.git,.hg,.svn}'
    alias grh='git reset HEAD'
    alias grhh='git reset HEAD --hard'
    alias grmv='git remote rename'
    alias grrm='git remote remove'
    alias grset='git remote set-url'
    alias grt='cd $(git rev-parse --show-toplevel || echo ".")'
    alias grup='git remote update'
    alias grv='git remote -v'
    alias gsd='git svn dcommit'
    alias gsps='git show --pretty=short --show-signature'
    alias gsr='git svn rebase'
    alias gss='git status -s'
    alias gst='git status'
    alias gsta='git stash'
    alias gstd='git stash drop'
    alias gstp='git stash pop'
    alias gsts='git stash show --text'
    alias gts='git tag -s'
    alias gunignore='git update-index --no-assume-unchanged'
    alias gunwip='git log -n 1 | grep -q -c "\-\-wip\-\-" && git reset HEAD~1'
    alias gup='git pull --rebase'
    alias gvt='git verify-tag'
    alias gwc='git whatchanged -p --abbrev-commit --pretty=medium'
    alias gwip='git add -A; git ls-files --deleted -z | xargs -r0 git rm; git commit -m "--wip--"'
    alias history='fc -l 1'
    alias l='ls -lah'
    alias la='ls -lAh'
    alias ll='ls -lh'
    alias ls='ls -G'
    alias lsa='ls -lah'
    alias po=popd
    alias pu=pushd
    alias v='f -e vim'
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82

    别小看短短的82行,可以实现的效率简直是提升了很多,下边shigen演示一下。

    • 查看文件的列表信息

    查看文件列表

    • 查看git历史

    查看git历史

    就先选取两个作为参考的案例啦,当然,还有很多实际的操作,这里偏重的是gitls命令的封装。

    其实shigen也自定义了脚本的命令,来一起看看吧。


    那我常用的python脚本查看IP地址为例,我用的时候只需要一个命令即可:

    IP查询工具

    but,我要是使用python命令去敲就麻烦了!

    原生的python命令

    那具体咋设置的呢,分享出来:

    ~/.bash_profile中添加如下的命令即可:

    alias ip-util="python3 ~/PycharmProjects/shigen-util/iputil/xdbSearcher.py"
    
    • 1

    接下来执行这个命令:

    source ~/.bash_profile
    
    • 1

    怎么查看ip-util是啥呢?

    which ip-util
    
    • 1

    which命令

    这样你就可以高效的操作命令了,接下来效率直接拉满。

    最后,最后再分享一个shigen觉得很有意思的命令:

    history | awk '{CMD[$2]++;count++;} END { for (a in CMD )print CMD[ a ]" " CMD[ a ]/count*100 "% " a }' | grep -v "./" | column -c3 -s " " -t |sort -nr | nl | head -n10
    
    • 1

    将这一行命令粘贴到控制台就可以看出我们使用的历史命令的top榜。

    历史命令top榜单

    这样,就可以把我们常用的命令再次alias一下,我们的效率就提升啦。


    以上就是今天分享的全部内容了,觉得不错的话,记得点赞 在看 关注支持一下哈,您的鼓励和支持将是shigen坚持日更的动力。同时,shigen在多个平台都有文章的同步,也可以同步的浏览和订阅:

    平台账号链接
    CSDNshigen01shigen的CSDN主页
    知乎gen-2019shigen的知乎主页
    掘金shigen01shigen的掘金主页
    腾讯云开发者社区shigenshigen的腾讯云开发者社区主页
    微信公众平台shigen公众号名:shigen

    shigen一起,每天不一样!

  • 相关阅读:
    【云原生之Docker实战】使用Docker部署Wizard文档管理系统
    《优化接口设计的思路》系列:第六篇—接口防抖(防重复提交)的一些方式
    基于 Habana Gaudi 的 Transformers 入门
    第二十七篇:稳定性之故障处理【初识故障与传播方式】
    Mathtype插入编号的高级格式会重置之前的简单格式的问题
    vscode代码上传到gitlab
    原生K8S部署pig微服务项目
    华清远见上海中心22071班--11.19作业
    链动2+1模式全新版本:会员自裂变,无限链动收益
    激光切割机加工过程中产生毛刺的原因及解决方案
  • 原文地址:https://blog.csdn.net/weixin_55768452/article/details/134497490