前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >mac终端命令小技巧

mac终端命令小技巧

原创
作者头像
shigen
发布2023-11-19 23:05:07
1370
发布2023-11-19 23:05:07
举报

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

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

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

shigen的iterm2
shigen的iterm2

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

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

我的alias

代码语言:shell
复制
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'

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

  • 查看文件的列表信息
查看文件列表
查看文件列表
  • 查看git历史
查看git历史
查看git历史

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

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


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

IP查询工具
IP查询工具

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

原生的python命令
原生的python命令

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

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

代码语言:shell
复制
alias ip-util="python3 ~/PycharmProjects/shigen-util/iputil/xdbSearcher.py"

接下来执行这个命令:

代码语言:shell
复制
source ~/.bash_profile

怎么查看ip-util是啥呢?

代码语言:shell
复制
which ip-util
which命令
which命令

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

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

代码语言:shell
复制
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

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

历史命令top榜单
历史命令top榜单

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


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

平台

账号

链接

CSDN

shigen01

知乎

gen-2019

掘金

shigen01

腾讯云开发者社区

shigen

微信公众平台

shigen

公众号名:shigen

shigen一起,每天不一样!

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 我的alias
相关产品与服务
云开发 CloudBase
云开发(Tencent CloudBase,TCB)是腾讯云提供的云原生一体化开发环境和工具平台,为200万+企业和开发者提供高可用、自动弹性扩缩的后端云服务,可用于云端一体化开发多种端应用(小程序、公众号、Web 应用等),避免了应用开发过程中繁琐的服务器搭建及运维,开发者可以专注于业务逻辑的实现,开发门槛更低,效率更高。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档