/pimp_my_laptop

addons to my vim and zsh

Primary LanguageShell

Menu

  1. Pimp My Vim
  2. Pimp My ZSH
  3. Mac
    1. Upgrade Bash
    2. Mofifier Keys
  4. IDE extensions
  5. Kubernetes

Pimp my Vim


Pimp my zsh

Set PYTHONPATH when in poetry environment

# Update PYTHONPATH with the project directory when entering a Poetry environment
function poetry_enter() {
  local project_dir
  project_dir=$(poetry run python -c 'import os; print(os.path.dirname(os.path.realpath("pyproject.toml")))')

  if [[ -n "$project_dir" ]]; then
    # Check if any parent directory is already present in PYTHONPATH
    local parent_dir
    parent_dir=$project_dir
    while [[ "$parent_dir" != "/" ]]; do
      if [[ ":$PYTHONPATH:" == *":$parent_dir:"* ]]; then
        return
      fi
      parent_dir=$(dirname "$parent_dir")
    done

    export PYTHONPATH="$project_dir:$PYTHONPATH"
  fi
}

# Remove PYTHONPATH when exiting a Poetry environment
function poetry_exit() {
  unset PYTHONPATH
}

# Check if current or parent directory contains the pyproject.toml file
function is_in_poetry_project() {
  local dir
  dir=$PWD
  while [[ "$dir" != "/" ]]; do
    if [[ -f "$dir/pyproject.toml" ]]; then
      return 0
    fi
    dir=$(dirname "$dir")
  done
  return 1
}

# Hook into directory changes and activate/deactivate PYTHONPATH accordingly
function chpwd() {
  if is_in_poetry_project; then
    poetry_enter
  else
    poetry_exit
  fi
}

iTerm Move cursor with ctrl + arrow keys

Set it to work using option (⌥) + arrows

bindkey "\e\e[D" backward-word
bindkey "\e\e[C" forward-word

Prefered Theme

Plugins

Modern Unix

  • Cool tools that helps making the terminal even better modern-unix

Aliases

alias lql='ls -lA *sql'
alias hg='history | grep'
alias pd='$HOME/workspace/scripts/pd.sh'
alias cat='bat'
#alias python='python3'
alias ipython='ipython3'
alias ptp='ptpython3'
alias stree='tree -I \'igore1|ignore2|ignore3_*\''

FZF

### fzf ############################
[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh
export FZF_DEFAULT_OPTS='-m --color fg:-1,bg:-1,hl:120,fg+:3,bg+:233,hl+:229 --color info:140,prompt:120,spinner:150,pointer:167,marker:174'
 # fe - Open the selected files with the default editor
fe() {
   local files=$(fzf --query="$1" --select-1 --exit-0 | sed -e "s/\(.*\)/\'\1\'/")
   local command="${EDITOR:-vim} -p $files"
   [ -n "$files" ] && eval $command
}
 # fag - find an argument with ag and fzf and open with vim
fag() {
 [ $# -eq 0  ] && return
 local out cols
 if out=$(ag --nogroup --color "$@" | fzf --ansi); then
   setopt sh_word_split
   cols=(${out//:/  })
   unsetopt sh_word_split
   vim ${cols[1]} +"normal! ${cols[2]}zz"
 fi
}
 # cdf - cd into the directory of the selected file\
cdf() {
  local file
  local dir
  file=$(fzf +m -q "$1") && dir=$(dirname "$file") && cd "$dir"
}
 fep() {
    local files=$(fzf --query="$1" --select-1 --exit-0 --preview="bat --color=always {}" --preview-window=right:50%:wrap | sed -e "s/\(.*\)/\'\1\'/")
    local command="${EDITOR:-vim} -p $files"
    [ -n "$files" ] && eval $command
}
#####################################

Other Stuff


pd.sh

#!/bin/bash
export LC_ALL=C
head /dev/urandom | tr -dc 'A-Za-z0-9"#$%&'\''()*+,-./:;<=>?@[\]^_`{|}~' | head -c 30 ; echo ''

Mac

Upgrade bash from 3.2.57 to 5.x

Mac comes with bash 3.2.57 due to licensing issues. in order to upgrade to the latest version (5.1.12 / Dec, 2021), run

brew install bash
newbash="$(echo $(brew --prefix)/bin/bash | sudo tee -a /private/etc/shells)"
sudo chpass -s $newbash

Modifier Keys

When using mac with external keyboard, it's best to modify the keys to comply with Mac layout. I set this way:

  • Caps Lock > Caps Lock
  • Control > Control
  • Option > Command
  • Command > Option
  • Function > fn (function)

Make sure to select the correct keyboard on the upper drop down menu.

Modify Keys


IDE extensions

  • Tabnine - TabNine uses deep learning to help you write code faster.

Kubernetes