├── .gitignore ├── LICENSE ├── README.md ├── bash_profile ├── bashrc ├── gitconfig ├── inputrc ├── linkfiles.sh ├── zshfunctions ├── closeman ├── git_vcs_setup ├── new ├── preman ├── project ├── pwdf ├── update_terminal_pwd ├── vnc ├── xmanpage ├── zcp └── zln └── zshrc /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | .DS_Store 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # dotfiles 2 | -------------------------------------------------------------------------------- /bash_profile: -------------------------------------------------------------------------------- 1 | # bash_profile 2 | # Armin Briegel 3 | 4 | # set a variable to know if this has run 5 | BASH_PROFILE_VERSION="2" 6 | 7 | # PATH 8 | export PATH=${PATH}:~/bin 9 | 10 | # print a message on SSH connection: 11 | if [[ -n "$SSH_CLIENT" ]]; then 12 | # ssh connection, print hostname and os version 13 | echo "Welcome to $(scutil --get ComputerName) ($(sw_vers -productVersion))" 14 | fi 15 | 16 | # PROMPT 17 | 18 | # default macOS prompt is: \h:\W \u\$ 19 | 20 | # assemble the prompt string PS1 21 | # inspired from: https://stackoverflow.com/a/16715681 22 | function __build_prompt { 23 | local EXIT="$?" # store current exit code 24 | 25 | # define some colors 26 | local RESET='\[\e[0m\]' 27 | local RED='\[\e[0;31m\]' 28 | local GREEN='\[\e[0;32m\]' 29 | local BOLD_GRAY='\[\e[1;30m\]' 30 | # longer list of codes here: https://unix.stackexchange.com/a/124408 31 | 32 | # start with an empty PS1 33 | PS1="" 34 | 35 | if [[ $EXIT -eq 0 ]]; then 36 | PS1+="${GREEN}√${RESET} " # Add green for success 37 | else 38 | PS1+="${RED}?️️️${EXIT}${RESET} " # Add red if exit code non 0 39 | fi 40 | # this is the default prompt for 41 | PS1+="${BOLD_GRAY}\W ${RESET}\$ " 42 | } 43 | 44 | # set the prompt command 45 | # include previous values to maintain Apple Terminal support (window title path and sessions) 46 | # this is explained in /etc/bashrc_Apple_Terminal 47 | PROMPT_COMMAND="__build_prompt${PROMPT_COMMAND:+; $PROMPT_COMMAND}" 48 | 49 | # make globbing case-insensitive 50 | shopt -s nocaseglob 51 | 52 | # make history file BIG 53 | export HISTSIZE=50000 54 | export HISTFILESIZE=50000 55 | 56 | # color 57 | export CLICOLOR=1 58 | 59 | # set EDITOR to bbedit 60 | if [[ -e "/usr/local/bin/bbedit" ]]; then 61 | export EDITOR="bbedit -w --resume" 62 | fi 63 | 64 | # ALIASES 65 | 66 | alias ll="ls -l" 67 | 68 | # Ring the terminal bell, and put a badge on Terminal.app’s Dock icon 69 | # (useful when executing time-consuming commands) 70 | alias badge="tput bel" 71 | 72 | alias ..="cd .." 73 | alias ...="cd ../.." 74 | alias cd..="cd .." 75 | 76 | alias reveal="open -R" 77 | 78 | alias pacifist='open -a "Pacifist"' 79 | 80 | # FUNCTIONS 81 | 82 | function vnc() { 83 | open vnc://"$USER"@"$1" 84 | } 85 | 86 | # man page functions 87 | 88 | function xmanpage() { open x-man-page://"$*" ; } 89 | alias xman=xmanpage 90 | alias man=xmanpage 91 | 92 | # editor functions 93 | function pllint () { 94 | plutil -lint "$*" | bbresults -p '(?P.+?):(?P.*\sline\s(?P\d+)\s.*)$' 95 | } 96 | 97 | function bbshellcheck { 98 | shellcheck -f gcc "$@" | bbresults 99 | } 100 | 101 | ## random colored background 102 | if [[ $TERM_PROGRAM == "Apple_Terminal" ]]; then 103 | if [[ -x ~/bin/randombackground ]]; then 104 | WINDOW_DARK_MODE=$(~/bin/randombackground) 105 | fi 106 | fi 107 | 108 | -------------------------------------------------------------------------------- /bashrc: -------------------------------------------------------------------------------- 1 | # check if bash_profile is already loaded (i.e. BASH_PROFILE_VERSION is set) 2 | 3 | if [[ -z $BASH_PROFILE_VERSION ]]; then 4 | if [[ -r ~/.bash_profile ]]; then 5 | source ~/.bash_profile 6 | fi 7 | fi 8 | -------------------------------------------------------------------------------- /gitconfig: -------------------------------------------------------------------------------- 1 | # GitConfig 2 | 3 | [filter "lfs"] 4 | clean = git-lfs clean -- %f 5 | smudge = git-lfs smudge -- %f 6 | process = git-lfs filter-process 7 | required = true 8 | [user] 9 | name = Armin Briegel 10 | email = 1933192+scriptingosx@users.noreply.github.com 11 | [init] 12 | defaultBranch = main 13 | [alias] 14 | co = checkout 15 | br = branch 16 | ci = commit 17 | st = status 18 | sts = status --short --branch 19 | ll = log --oneline --graph --all 20 | [diff] 21 | tool = bbdiff 22 | guitool = bbdiff 23 | [difftool] 24 | [difftool "bbdiff"] 25 | path=/usr/local/bin 26 | cmd=bbdiff --wait --resume $LOCAL $REMOTE 27 | prompt = false 28 | [merge] 29 | tool = opendiff 30 | [mergetool] 31 | prompt = false 32 | trustExitCode = false 33 | 34 | # starting point: https://blog.gitbutler.com/how-git-core-devs-configure-git/ 35 | 36 | # clearly makes git better 37 | 38 | [column] 39 | ui = auto 40 | [branch] 41 | sort = -committerdate 42 | [tag] 43 | sort = version:refname 44 | [diff] 45 | algorithm = histogram 46 | colorMoved = plain 47 | mnemonicPrefix = true 48 | renames = true 49 | [push] 50 | default = simple 51 | autoSetupRemote = true 52 | followTags = true 53 | [fetch] 54 | prune = true 55 | pruneTags = true 56 | all = true 57 | 58 | # why the hell not? 59 | 60 | [help] 61 | autocorrect = prompt 62 | [commit] 63 | verbose = true 64 | [rerere] 65 | enabled = true 66 | autoupdate = true 67 | [core] 68 | # excludesfile = ~/.gitignore 69 | [rebase] 70 | # autoSquash = true 71 | # autoStash = true 72 | # updateRefs = true 73 | 74 | # a matter of taste (uncomment if you dare) 75 | 76 | [core] 77 | # fsmonitor = true 78 | # untrackedCache = true 79 | [merge] 80 | # (just 'diff3' if git version < 2.3) 81 | # conflictstyle = zdiff3 82 | [pull] 83 | # rebase = true -------------------------------------------------------------------------------- /inputrc: -------------------------------------------------------------------------------- 1 | # Ignore case while completing 2 | set completion-ignore-case on 3 | -------------------------------------------------------------------------------- /linkfiles.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | export PATH=/bin:/usr/bin:/sbin:/usr/sbin 4 | 5 | # function to create a symlink 6 | symlink () { # srcdir destdir [srcItem] item 7 | # even though the links point to the absolute path 8 | if [ -e "$1/$3" ]; then 9 | if [ ! -z "$4" ]; then 10 | ln -sFi "$1/$3" "$2/$4" 11 | else 12 | ln -sFi "$1/$3" "$2/$3" 13 | fi 14 | else 15 | echo "no file: $1/$3" 16 | fi 17 | } 18 | 19 | linkproject() { # projectdir [srcItem] item 20 | if [ $# -eq 1 ]; then 21 | symlink "${PROJECTS}/$1" "${BIN_FOLDER}" "$1" 22 | elif [ $# -eq 2 ]; then 23 | symlink "${PROJECTS}/$1" "${BIN_FOLDER}" "$2" 24 | else 25 | symlink "${PROJECTS}/$1" "${BIN_FOLDER}" "$2" "$3" 26 | fi 27 | } 28 | 29 | MY_PATH=$(cd $(dirname "${BASH_SOURCE[0]}") && pwd) 30 | 31 | symlink "${MY_PATH}" "${HOME}" "inputrc" ".inputrc" 32 | symlink "${MY_PATH}" "${HOME}" "bash_profile" ".bash_profile" 33 | symlink "${MY_PATH}" "${HOME}" "bashrc" ".bashrc" 34 | symlink "${MY_PATH}" "${HOME}" "zshrc" ".zshrc" 35 | symlink "${MY_PATH}" "${HOME}" "gitconfig" ".gitconfig" 36 | 37 | PROJECTS=$(dirname "$MY_PATH") 38 | echo "Projects Folder: $PROJECTS" 39 | 40 | BIN_FOLDER="${HOME}/bin" 41 | mkdir -m 750 "${BIN_FOLDER}" 42 | echo "bin folder: $BIN_FOLDER" 43 | 44 | # look for certain git projects in the Projects folder and link the executable to ~/bin 45 | #linkproject "make-profile-pkg" "make_profile_pkg.py" "make_profile_pkg" 46 | #linkproject "mcxToProfile" "mcxToProfile.py" "mcxToProfile" 47 | #linkproject "recipeutil" 48 | #linkproject "RemindersCLITool" "reminders" 49 | #linkproject "thingsCLITool" "things" 50 | linkproject "munki-pkg" "munkipkg" 51 | linkproject "quickpkg" 52 | #linkproject "ssh-installer" "ssh-installer.sh" "ssh-installer" 53 | -------------------------------------------------------------------------------- /zshfunctions/closeman: -------------------------------------------------------------------------------- 1 | # closes all Terminal windows with the profile "Man Page" 2 | 3 | osascript -e 'tell application "Terminal" to close (every window where name of current settings of every tab contains "Man Page")' 4 | -------------------------------------------------------------------------------- /zshfunctions/git_vcs_setup: -------------------------------------------------------------------------------- 1 | # git_vcs_setup 2 | 3 | # sets up Window title and right prompt to show git branch and repo 4 | 5 | # slightly modified from: 6 | # https://git-scm.com/book/en/v2/Appendix-A%3A-Git-in-Other-Environments-Git-in-Zsh 7 | 8 | autoload -Uz vcs_info 9 | 10 | # this updates just the window title 11 | update_terminal_window_title() { 12 | printf '\e]2;%s\a' "$@" 13 | } 14 | 15 | # in Terminal tabs can have a title separate from the Window 16 | update_terminal_tab_title() { 17 | printf '\e]1;%s\a' "$@" 18 | } 19 | 20 | 21 | # this function will be called to set the info 22 | precmd_vcs_info() { 23 | vcs_info 24 | update_terminal_tab_title $vcs_info_msg_0_ 25 | } 26 | 27 | setopt prompt_subst 28 | RPROMPT='%F{240}$vcs_info_msg_0_%f' 29 | # PROMPT='\$vcs_info_msg_0_%# ' 30 | 31 | # enables checking for staged/unstaged 32 | zstyle ':vcs_info:*' check-for-changes true 33 | 34 | # set the format for $vcd_info_msg_0 strings 35 | # %s: vcs service (in our case 'git') 36 | # %r: repository name 37 | # %b: branch name 38 | # %u: 'U' if there are unstaged files 39 | # %c: 'S' if there are staged, but uncommitted files 40 | 41 | zstyle ':vcs_info:git:*' formats '%b:%u%c' 42 | 43 | # enable just git 44 | zstyle ':vcs_info:*' enable git 45 | 46 | # http://zsh.sourceforge.net/Doc/Release/User-Contributions.html#Version-Control-Information 47 | 48 | autoload add-zsh-hook 49 | add-zsh-hook precmd precmd_vcs_info 50 | -------------------------------------------------------------------------------- /zshfunctions/new: -------------------------------------------------------------------------------- 1 | # creates a new terminal window 2 | function new() { 3 | if [[ "$TERM_PROGRAM" == "iTerm.app" ]]; then 4 | app_name="iTerm" 5 | else 6 | app_name="Terminal" 7 | fi 8 | 9 | if [[ $# -eq 0 ]]; then 10 | open -a "$app_name" "$PWD" 11 | else 12 | open -a "$app_name" "$@" 13 | fi 14 | } 15 | -------------------------------------------------------------------------------- /zshfunctions/preman: -------------------------------------------------------------------------------- 1 | # opens man page in Preview 2 | 3 | mandoc -T pdf "$(/usr/bin/man -w $@)" | open -fa Preview 4 | -------------------------------------------------------------------------------- /zshfunctions/project: -------------------------------------------------------------------------------- 1 | # finds a directory in projects and opens in Terminal, bbedit and Finder 2 | function project() { 3 | local project=${1:?"first argument should be the name of the project"} 4 | 5 | if [[ -z $PROJECTS_DIR ]]; then 6 | echo "no PROJECTS_DIR variable set" 7 | return 1 8 | fi 9 | 10 | local projects_path=$PROJECTS_DIR 11 | 12 | for p in $PROJECTS_DIR/**/$project; do 13 | project_path=${p:A} 14 | break 15 | done 16 | 17 | # if the folder doesn't exist, do nothing 18 | if [[ ! -d "$project_path" ]]; then 19 | echo "could not find $project in $projects_path" 20 | return 1 21 | fi 22 | 23 | echo "$project_path" 24 | 25 | # cd to the folder 26 | cd "$project_path" 27 | 28 | if [[ -d .git ]]; then 29 | git status 30 | fi 31 | 32 | # is there an Xcode project? 33 | if [[ -n $(find . -name "*.xcodeproj" -maxdepth 1) ]]; then 34 | # open in Xcode 35 | xed . 36 | return 37 | fi 38 | 39 | # is there a Package.swift? 40 | if [[ -f "Package.swift" ]]; then 41 | # open in Xcode 42 | xed . 43 | return 44 | fi 45 | 46 | # open folder in BBEdit 47 | bbedit . 48 | 49 | # open folder in Finder 50 | open . 51 | 52 | # bring Terminal to front 53 | open -a "Terminal" 54 | } -------------------------------------------------------------------------------- /zshfunctions/pwdf: -------------------------------------------------------------------------------- 1 | # prints the path of the front Finder window. Desktop if no window open 2 | 3 | # use an alias to change to the current finder window 4 | # alias cdf='pwdf; cd "$(pwdf)"' 5 | function pwdf() { 6 | finder_path=$( osascript <<- EndOfScript 7 | tell application "Finder" 8 | if (count of Finder windows) is 0 then 9 | set dir to (desktop as alias) 10 | else 11 | set dir to ((target of Finder window 1) as alias) 12 | end if 13 | return POSIX path of dir 14 | end tell 15 | EndOfScript 16 | ) 17 | if [[ $1 != "-notilde" ]]; then 18 | # this correctly inserts '~' 19 | print -rD $finder_path 20 | else 21 | print $finder_path 22 | fi 23 | } 24 | 25 | alias cdf='pwdf; cd $(pwdf -notilde )' 26 | -------------------------------------------------------------------------------- /zshfunctions/update_terminal_pwd: -------------------------------------------------------------------------------- 1 | # function to update terminal title bar current working dir 2 | # (borrowed from /etc/bashrc_Apple_Terminal) 3 | update_terminal_cwd() { 4 | # Identify the directory using a "file:" scheme URL, including 5 | # the host name to disambiguate local vs. remote paths. 6 | 7 | # Percent-encode the pathname. 8 | local url_path='' 9 | { 10 | # Use LC_CTYPE=C to process text byte-by-byte. Ensure that 11 | # LC_ALL isn't set, so it doesn't interfere. 12 | local i ch hexch LC_CTYPE=C LC_ALL= 13 | for (( i = 1; i <= ${#PWD}; ++i)); do 14 | ch="$PWD[i]" 15 | if [[ "$ch" =~ [/._~A-Za-z0-9-] ]]; then 16 | url_path+="$ch" 17 | else 18 | printf -v hexch "%02X" "'$ch" 19 | # printf treats values greater than 127 as 20 | # negative and pads with "FF", so truncate. 21 | url_path+="%${hexch: -2:2}" 22 | fi 23 | done 24 | } 25 | printf '\e]7;%s\a' "file://$HOST$url_path" 26 | } 27 | 28 | # add a function to update window title cwd on dir change 29 | autoload add-zsh-hook 30 | add-zsh-hook chpwd update_terminal_cwd 31 | 32 | # since the function will run on _changing_ the dir 33 | # it won't run automatically at shell start 34 | # so, run it once now, to update: 35 | update_terminal_cwd 36 | -------------------------------------------------------------------------------- /zshfunctions/vnc: -------------------------------------------------------------------------------- 1 | # uses the arguments as hostnames for `open vnc://` (Screen Sharing) 2 | # uses the $USER username as default account name 3 | function vnc() { 4 | for x in $@; do 5 | open vnc://"$USER"@"$x" 6 | done 7 | } 8 | -------------------------------------------------------------------------------- /zshfunctions/xmanpage: -------------------------------------------------------------------------------- 1 | # if there is a single argument, open its man page using the URL 2 | # this opens the 'yellow' single window man page in Terminal.app 3 | 4 | # if there are two arguments, interpret the first as the section 5 | # the section has to come _first_ in the URL 6 | 7 | if [[ -z $2 ]]; then 8 | open x-man-page://"$1" 9 | else 10 | open x-man-page://"$1"/"$2" 11 | fi 12 | -------------------------------------------------------------------------------- /zshfunctions/zcp: -------------------------------------------------------------------------------- 1 | /usr/share/zsh/5.7.1/functions/zmv -------------------------------------------------------------------------------- /zshfunctions/zln: -------------------------------------------------------------------------------- 1 | /usr/share/zsh/5.7.1/functions/zmv -------------------------------------------------------------------------------- /zshrc: -------------------------------------------------------------------------------- 1 | # zshrc 2 | # Armin Briegel 3 | 4 | # set a profile version 5 | ZSHRC_VERSION="2020-10-14" 6 | 7 | 8 | ## random colored background 9 | ## I put this early, otherwise it might happen to late when multiple windows are opened 10 | if [[ $TERM_PROGRAM == "Apple_Terminal" ]]; then 11 | if [[ -x ~/bin/randombackground ]]; then 12 | ~/bin/randombackground 13 | fi 14 | fi 15 | 16 | 17 | # path to directory containing repositories 18 | if [[ -d ~/Developer ]]; then 19 | repo_dir=~/Developer 20 | elif [[ -d ~/Projects ]]; then 21 | repo_dir=~/Projects 22 | fi 23 | 24 | PROJECTS_DIR=$repo_dir 25 | 26 | autoload project 27 | 28 | # path to my zsh functions folder: 29 | my_zsh_functions=$repo_dir/dotfiles/zshfunctions/ 30 | 31 | # path to mac completions dir 32 | mac_completion_dir=$repo_dir/mac-zsh-completions/completions/ 33 | 34 | 35 | # PATH 36 | 37 | # prevent duplicate entries in path 38 | declare -U path 39 | 40 | path+=~/bin 41 | 42 | 43 | # PROMPT 44 | 45 | # only for Mojave and earlier 46 | if [[ $(sw_vers -buildVersion) < "19" ]]; then 47 | # this sets up the connection with the Apple Terminal Title Bar 48 | autoload -U update_terminal_pwd && update_terminal_pwd 49 | fi 50 | 51 | # Actual Prompt 52 | 53 | # %(?.√.?%?) : if return code `?` is 0, show `√`, else show `?%?` 54 | # %? : exit code of previous command 55 | # %1~ : current working dir, shortening home to `~`, show the last `1` element 56 | # %# : `#` if root, `%` otherwise 57 | # %B %b : start/stop bold 58 | # %F{...} : colors, see https://www.calmar.ws/vim/256-xterm-24bit-rgb-color-chart.html 59 | # %f : reset to default color 60 | # %(!. : conditional depending on privileged user 61 | PROMPT='%(?..%F{red}?%? )%B%F{240}%1~%b%f %(?.%F{green}.%F{red})%(!.#.➜)%f ' 62 | 63 | # SHELL OPTIONS 64 | 65 | # enable extended globbing features 66 | setopt EXTENDED_GLOB 67 | # case insensitive globbing 68 | setopt NO_CASE_GLOB 69 | # sort extensions with numbers numerically 70 | setopt NUMERIC_GLOB_SORT 71 | 72 | # Enable Auto cd 73 | setopt AUTO_CD 74 | 75 | 76 | # HISTORY 77 | 78 | # history file 79 | HISTFILE=${ZDOTDIR:-$HOME}/.zsh_history 80 | HISTSIZE=20000 # lines remembered per session 81 | SAVEHIST=20000 # lines stored in history file 82 | 83 | # store more information (timestamp) 84 | setopt extended_history 85 | 86 | # shares history across multiple zsh sessions 87 | setopt share_history 88 | # append to history 89 | setopt append_history 90 | 91 | # expire duplicates first 92 | setopt hist_expire_dups_first 93 | # do not store duplications, keep newest 94 | setopt hist_ignore_all_dups 95 | #ignore duplicates when searching 96 | setopt hist_find_no_dups 97 | # removes blank lines from history 98 | setopt hist_reduce_blanks 99 | 100 | # when using history expansion (!!, !$, etc.), present for confirmation/editing 101 | setopt hist_verify 102 | 103 | ## Correction 104 | 105 | # Correct commands 106 | setopt CORRECT 107 | # Correct all arguments 108 | setopt CORRECT_ALL 109 | 110 | # correction prompt 111 | SPROMPT="Correct %F{red}%R%f to %F{green}%r%f [nyae]?" 112 | 113 | # exceptions 114 | alias swift="nocorrect swift" 115 | 116 | # KEY BINDINGS 117 | 118 | bindkey $'^[[A' up-line-or-search # up arrow 119 | bindkey $'^[[B' down-line-or-search # down arrow 120 | 121 | # COMPLETION 122 | 123 | # add my completion folder to fpath 124 | # (don't do this for root shells to avoid security warning) 125 | if [[ $EUID -ne 0 ]]; then 126 | if [[ -d $mac_completion_dir ]]; then 127 | fpath=( $mac_completion_dir $fpath ) 128 | fi 129 | fi 130 | 131 | # case insensitive path-completion 132 | 133 | zstyle ':completion:*' matcher-list 'm:{[:lower:][:upper:]}={[:upper:][:lower:]}' 'm:{[:lower:][:upper:]}={[:upper:][:lower:]} l:|=* r:|=*' 'm:{[:lower:][:upper:]}={[:upper:][:lower:]} l:|=* r:|=*' 'm:{[:lower:][:upper:]}={[:upper:][:lower:]} l:|=* r:|=*' 134 | 135 | # show descriptions when autocompleting 136 | zstyle ':completion:*' auto-description 'specify: %d' 137 | zstyle ':completion:*' format 'Completing %d' 138 | 139 | # partial completion suggestions 140 | zstyle ':completion:*' list-suffixes true 141 | zstyle ':completion:*' expand prefix suffix 142 | 143 | # list with colors 144 | zstyle ':completion:*' list-colors ''x 145 | 146 | # load completion 147 | autoload -Uz compinit && compinit 148 | 149 | # load bashcompinit for some old bash completions 150 | #autoload bashcompinit && bashcompinit 151 | 152 | # autopkg completion 153 | #[[ -r $repo_dir/autopkg_complete/autopkg ]] && source $repo_dir/autopkg_complete/autopkg 154 | 155 | # enable arrow key menu for completion 156 | #zstyle ':completion:*' menu select 157 | 158 | # print a message on SSH connection: 159 | if [[ -n "$SSH_CLIENT" ]]; then 160 | # ssh connection, print hostname and os version 161 | echo "Welcome to $(scutil --get ComputerName) ($(sw_vers -productVersion))" 162 | fi 163 | 164 | 165 | # ENVIRONMENT VARIABLES 166 | 167 | export CLICOLOR=1 168 | 169 | 170 | # ALIASES 171 | 172 | alias ll="ls -lG" 173 | 174 | alias reveal="open -R" 175 | 176 | alias pacifist='open -a "Pacifist"' 177 | 178 | # Ring the terminal bell, and put a badge on Terminal.app’s Dock icon 179 | # (useful when executing time-consuming commands) 180 | alias -g badge="tput bel" 181 | 182 | # re-define and autoload run-help 183 | HELPDIR=/usr/share/zsh/5.8/help 184 | unalias run-help 185 | autoload run-help 186 | alias help=run-help 187 | 188 | # Suffix Aliases 189 | 190 | # alias -s txt=bbedit 191 | # alias -s log="open -a Console" 192 | # alias -s pkg=pacifist 193 | # alias -s plist=pledit 194 | 195 | # note disabled suffix aliases because they are confusing with auto-suggestion 196 | 197 | # FUNCTIONS 198 | 199 | # include my zshfunctions dir in fpath: 200 | # (don't do this for root shells to avoid security warning) 201 | if [[ $EUID -ne 0 ]]; then 202 | if [[ -d $my_zsh_functions ]]; then 203 | fpath=( $my_zsh_functions $fpath ) 204 | fi 205 | # prints path to frontmost finder window 206 | autoload pwdf && pwdf 207 | 208 | # vnc opens screen sharing 209 | autoload vnc 210 | 211 | # man page functions 212 | autoload preman 213 | autoload closeman 214 | autoload xmanpage 215 | alias xman=xmanpage 216 | alias man=xmanpage 217 | 218 | # Git status 219 | autoload -U git_vcs_setup && git_vcs_setup 220 | fi 221 | 222 | # editor functions 223 | 224 | # set EDITOR to bbedit 225 | if [[ -x "/usr/local/bin/bbedit" ]]; then 226 | export EDITOR="/usr/local/bin/bbedit -w --resume" 227 | fi 228 | 229 | # bat configuration 230 | # https://github.com/sharkdp/bat 231 | if [[ -x /usr/local/bin/bat ]]; then 232 | export BAT_THEME=ansi-light 233 | fi 234 | 235 | # show plutil -lint results in bbedit 236 | function pllint () { 237 | plutil -lint "$*" | bbresults -p '(?P.+?):(?P.*\sline\s(?P\d+)\s.*)$' 238 | } 239 | 240 | # show shellcheck results in bbedit 241 | function bbshellcheck { 242 | shellcheck -f gcc "$@" | bbresults 243 | } 244 | 245 | ## some plug-ins 246 | 247 | # zsh-autosuggestions 248 | # https://github.com/zsh-users/zsh-autosuggestions/blob/master/INSTALL.md 249 | [[ -f $repo_dir/zsh-autosuggestions/zsh-autosuggestions.zsh ]] && source $repo_dir/zsh-autosuggestions/zsh-autosuggestions.zsh 250 | 251 | ZSH_AUTOSUGGEST_STRATEGY=( completion history ) 252 | 253 | # zsh-syntax-highlighting 254 | # (note, according to their docs, this must be loaded _LAST_) 255 | # https://github.com/zsh-users/zsh-syntax-highlighting/blob/master/INSTALL.md 256 | [[ -f $repo_dir/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh ]] && source $repo_dir/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh 257 | 258 | # always return true 259 | true 260 | --------------------------------------------------------------------------------