Category: macOS

  • brew 切换 python 版本

    切换 python 至 3.6.5

    brew list python --versions
    brew switch python 3.6.5
    

    升级 python3

    brew install python3
    

    link 切换

    ➜  ✗ brew link python
    Linking /usr/local/Cellar/python/3.7.7... 
    Error: Could not symlink Frameworks/Python.framework/Headers
    Target /usr/local/Frameworks/Python.framework/Headers
    is a symlink belonging to python@2. You can unlink it:
      brew unlink python@2
    解除 python@2 link
    Unlinking /usr/local/Cellar/python@2/2.7.17... 34 symlinks removed
    
    
    To force the link and overwrite all conflicting files:
      brew link --overwrite python
    
    To list all files that would be deleted:
      brew link --overwrite --dry-run python
    ➜  ✗ brew link python --overwrite python
    Linking /usr/local/Cellar/python/3.7.7... 28 symlinks created
    
  • macOS 屏幕相关

    1. mission control => 触发角 => 启用屏幕保护程序 or 将显示器置入睡眠状态
    2. 安全性与隐私 => 进入睡眠或开始屏幕保护程序 立即 要求输入密码

    接下来使用触发角就可以立即锁屏了

    新版 mac 使用 ctrl + command + q

    Question: how to quick switch between mirror and extended display in macOS
    切换 mirror 和 扩展模式: command + F1
    If you need to temporarily see your Dock or your open windows on both displays, Command-F1 lets you accomplish this. It’s a shortcut to the System Preferences > Displays > Arrangement > Mirror Displays command.

  • macOS iCloud Drive path

    The path of iCloud Drive is

    ~/Library/Mobile\ Documents/com~apple~CloudDocs

    How to find this path
    Finder => View => Show Path Bar => Open iCloud Drive, in the bottom, right click, we can Copy “iCloud Drive” as Pathname

    We can create a symbolic link for the path

    ln -s ~/Library/Mobile\ Documents/com\~apple\~CloudDocs icloud

    Or an alias, cdi equals change directory to iCloud Drive

    alias cdi='cd ~/Library/Mobile\ Documents/com~apple~CloudDocs'
  • brew安装多版本 清理包和 img

    brew 安装多版本

    例子,当前 gradle 5.2.1 ,想将 4.10.2 装上,找到 formula 的 git 目录,切到对应 4.10.2 的 commit,安装,安装完之后再切回 master

    $ brew list gradle --versions
    gradle 5.2.1
    $ cd "$(brew --repo homebrew/core)"
    $ pwd
    /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core
    $ git log master -- Formula/gradle.rb 
    ...
    commit 01e0511df2c37b052a9659797f3c09df3f20d533
    Author: Jerome Lapostolet 
    Date:   Thu Sep 20 08:51:53 2018 +0100
    
        gradle 4.10.2
    ...
    
    $ git checkout 01e0511df2c37b052a9659797f3c09df3f20d533
    Note: checking out '01e0511df2c37b052a9659797f3c09df3f20d533'.
    
    You are in 'detached HEAD' state. You can look around, make experimental
    changes and commit them, and you can discard any commits you make in this
    state without impacting any branches by performing another checkout.
    
    If you want to create a new branch to retain commits you create, you may
    do so (now or later) by using -b with the checkout command again. Example:
    
      git checkout -b 
    
    HEAD is now at 01e0511df2 gradle 4.10.2
    $ HOMEBREW_NO_AUTO_UPDATE=1 brew install gradle
    Error: gradle 5.2.1 is already installed
    To install 4.10.2, first run `brew unlink gradle`.
    $ HOMEBREW_NO_AUTO_UPDATE=1 brew unlink gradle
    Unlinking /usr/local/Cellar/gradle/5.2.1... 1 symlinks removed
    $ HOMEBREW_NO_AUTO_UPDATE=1 brew install gradle
    ==> Downloading https://services.gradle.org/distributions/gradle-4.10.2-all.zip
    ==> Downloading from https://downloads.gradle.org/distributions/gradle-4.10.2-all.zip
    ######################################################################## 100.0%
    🍺  /usr/local/Cellar/gradle/4.10.2: 203 files, 83.7MB, built in 5 minutes 56 seconds
    $ git checkout master
    
    $ brew list gradle --versions
    gradle 5.2.1 4.10.2
    
    

    之后可以用 brew swith gradle x.x.x 在不同版本之间切换
    helm 安装 v2.9.1 版本

    https://medium.com/@nehaguptag/installing-older-version-of-helm-downgrading-helm-8f3240592202
    wget https://raw.githubusercontent.com/Homebrew/homebrew-core/78d64252f30a12b6f4b3ce29686ab5e262eea812/Formula/kubernetes-helm.rb
    brew install kubernetes-helm.rb
    

    查看已经安装的包

    brew list

    选择要清理的包

    brew uninstall mariadb

    整体清理

    brew update && brew upgrade && brew cleanup
    
    ==> This operation has freed approximately 427.8M of disk space.
    brew cask cleanup

    https://brew.sh/ 搜索软件和版本

    检查当前 brew 的配置情况

    brew doctor                                                                                               master 187b0c8b0d
    Please note that these warnings are just used to help the Homebrew maintainers
    with debugging if you file an issue. If everything you use Homebrew for is
    working fine: please don't worry or file an issue; just ignore this. Thanks!
    
    Warning: Some installed kegs have no formulae!
    This means they were either deleted or installed with `brew diy`.
    You should find replacements for the following formulae:
      python@2
      ab
      tuntap
      unrar
      sshpass
      php54
    
    Warning: Some installed formulae are deprecated or disabled.
    You should find replacements for the following formulae:
      dep
      docker-machine
      [email protected]
      sshfs
    
    Warning: Unbrewed dylibs were found in /usr/local/lib.
    If you didn't put them there on purpose they could cause problems when
    building Homebrew formulae, and may need to be deleted.
    
    Unexpected dylibs:
      /usr/local/lib/libD4P11_ICBC.dylib
      /usr/local/lib/libD4PinPad_ICBC.dylib
      /usr/local/lib/libD4Token_ICBC.dylib
      /usr/local/lib/libshuttle_p11v220.1.0.0.dylib
    
    Warning: You have unlinked kegs in your Cellar.
    Leaving kegs unlinked can lead to build-trouble and cause formulae that depend on
    those kegs to fail to run properly once built. Run `brew link` on these:
      tree
      pandoc
      docker
      python@2
      docker-machine
      ab
      markdown
      tuntap
      aria2
      geoip
      unixodbc
      unrar
      gd
      wireshark
      php54
    
    Warning: Some taps are not on the default git origin branch and may not receive
    updates. If this is a surprise to you, check out the default branch with:
      git -C $(brew --repo homebrew/core) checkout master
    
    Warning: Homebrew's "sbin" was not found in your PATH but you have installed
    formulae that put executables in /usr/local/sbin.
    Consider setting your PATH for example like so:
      echo 'export PATH="/usr/local/sbin:$PATH"' >> ~/.zshrc
    
    
    

    参考:
    https://www.cnblogs.com/BlackStorm/p/homebrew-install-old-versions-take-node-for-example.html

  • git notes

    level 6

    rebase

    git fetch只获取,并不合并

    本地与远端使用git rebase
    git rebase进行了三步操作

    把所有master的改变放到一个临时区域里面

    运行所有origin/master的提交

    运行在临时区域的commits

    本地两个分支间的rebase,master和  develop均有提交

    在develop分支下,

    git rebase master

    然后再git checkout master

    把develp合并过来

    git merge develop

    conflicts本地master和远端origin/master都修改了同一个文件,并在本地提交

    解决冲突

    在master上git fetch

    然后git rebase,这样保证在master上有最新的代码

    这里会提示有冲突

    当解决了问题,则用git rebase –continue

    level 7

    git log
    sha hash

    git config –global color.ui true

    git log –pretty=oneline

    git log –oneline –stat

    当前分支与 master 的区别

    git log --oneline  ...master
    

    git log -p 查看具体的改变

    git diff  == git diff HEAD
    git diff HEAD^

    git diff HEAD~5
    git diff HEAD^..HEAD

    git diff sha..sha
    git diff master develop

    对于单个文件一直以来的变化
    git blame index.html –date short
    git status 看到有不想提交的,则在 .git/info/exclude 把文件过滤掉

    .gitignore
    git 删除文件
    git rm README.txt
    在 system 中不会被删除,但在 git 中会删除
    git rm –cached development.log

    mac 指定 merge 工具

    git config --global merge.tool opendiff
    git config --global alias.st status 来设置 status 的别名
    

    level 4

    git push rejected
    

    首先git pull

    pull的动做细分

    git fetch到origin/master

    将origin/master合并到本地  master

    git merge origin/master

    现在再push

    conflict

    必须手动解决

    level 1

    查看staged文件做了哪些改动

    git diff –staged

    在提交的同时进行添加

    git commit -a -m “add index”

    将修改的文件恢复

    git checkout — cats.html index.html

    level 2

    undo上一次提交,并将改变放到 staging 中

    git reset --soft HEAD^

    只修改上一次的提交

    git commit --amend -m "New Message"
    

    undo 上一次的提交和修改,你的修改会丢失

    git reset --hard HEAD^

    undo 上两次的提交和修改

    git reset --hard HEAD^^

    git reset HEAD ostrich.html

    查看远端的 fetch 及 push地址
    git remote -v

    git remote add <name> <address>

    删除远端 repo
    git remote rm <name>

    git push -u origin master

    origin是远端 repo 的名字, master 是本地分支的名字

    设置 git config user

    git config --global --edit
    #全局配置在 ~/.gitconfig
    [user]
        name = myusername
        email = [email protected]
    
    当前项目配置在
    .git/config
    

    想要保存一个空目录时,一般添加一个空文件.gitkeep,比如

    secrets/.gitkeep

    macOS 自动保存到 keychain

    git config --global credential.helper osxkeychain
    
  • mac terminal 查词典

    在 mac 的 terminal 下打开词典并查 blog

    open dict://blog

    要输入的命令有点长,于是在 ~/.zshrc 中添加函数

    dict(){
      open dict://$1
    }

    在 terminal 中可以这样查 dict blog