1 终端模糊搜索fzf
https://github.com/junegunn/fzf
输入某命令,比如 conda
,按下ctrl+R,会显示和该命令匹配的历史命令的列表
有了这个工具再也不用记忆太复杂的命令,只需要知道大概几个单词,输入即可搜索。
其搜索源来自于 vim ~/.zsh_history, 这个文件被fzf工具创建,其会记录所有terminal输入过的命令。
2 bash的最佳替代品 —— Oh-My-Zsh
https://github.com/zeus911/blog-3/blob/master/others/install-and-use-oh-my-zsh.md
3 GitHelper私货工具
文件1:git_helper.py
import click
import subprocess
def run_git_command(*args):
subprocess.run(['git', *args])
@click.group()
@click.option('--helper', is_flag=True, help='Display help information')
def git_helper(helper):
if helper:
click.echo('Usage:')
click.echo(
'start <branch_name> --remote_branch=specific_remote_branch_name: '
'Fetches the specified remote branch, then creates a local branch with this name based'
' on the fetched branch. If remote_branch is not specified, it defaults to master.')
click.echo(
'sync --remote_branch=specific_remote_branch_name: Rebases the current local '
'branch onto the specified remote branch. If not specified, defaults to rebase onto '
'master.')
return
def fetch(remote_branch):
run_git_command('fetch', 'origin', remote_branch)
@git_helper.command()
@click.argument('branch_name')
@click.option('--remote_branch', default='master',
help='Specify the remote branch, default is master')
def start(branch_name, remote_branch):
fetch(remote_branch)
run_git_command('checkout', '-b', branch_name, f'origin/{remote_branch}')
@git_helper.command()
@click.option('--remote_branch', default='master',
help='Specify the remote branch, default is master')
def sync(remote_branch):
fetch(remote_branch)
run_git_command('rebase', f'origin/{remote_branch}')
if __name__ == '__main__':
git_helper()
文件2:git_helper.sh
#!/usr/bin/zsh
alias git_helper="python /path/to/git_helper.py"
alias g_sync="git_helper sync"
alias g_start="git_helper start"
alias g_delete='git branch -D'
alias gst='git status'
alias gsc='git add . && git commit'
alias gc='git checkout'
alias gb='git branch --list | cat'
在.bashrc或者.zshrc中添加
source path/to/git_helper.sh
使用方法
- 创建分支
# 将会以{REMOTE_BRANCH_NAME}为base,在本地创建一个名字为{YOUR_BRANCH_NAME}的与其相同的分支。如果不指定--remote_branch参数,将默认以远程master为base创建本地分支。
g_start YOUR_BRANCH_NAME --remote_branch REMOTE_BRANCH_NAME
- 同步分支Sync或者说rebase当前分支
# 将当前所在分支sync到指定的{REMOTE_BRANCH_NAME}分支上(本质是rebase),如果不指定默认sync到master分支
g_sync --remote_branch REMOTE_BRANCH_NAME
- 其他简单命令
g_delete YOUR_BRANCH_NAME # 删除指定分支(不能删除当前分支)
gst # 相当于 git status
gsc # 相当于 git add . && git commit
gc YOUR_BRANCH_NAME # 切换到指定分支,相当于 git checkout
gb # 列出当前所有分支
借助g_start, g_sync, gsc, gc 这四个命令即可覆盖99%的git日常使用。