Skip to content

omersi/pimp_my_laptop

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 () {
	local dir_pattern=""
	local search_args=()
	local ignore_args=()
	local arg_parse_ignore=false
	while [[ "$1" =~ ^- && ! "$1" == "--" ]]
	do
		case $1 in
			(-h) echo "Usage: fag [options] search_term -- ignore_pattern1 ignore_pattern2 ..."
				echo "Options:"
				echo "  -h            Show this help message and exit."
				echo "  -d            Specify a custom directory pattern to search within."
				return ;;
			(-d) shift
				dir_pattern="$1"  ;;
		esac
		shift
	done
	if [[ "$1" == "--" ]]
	then
		shift
	fi
	while [[ $# -gt 0 ]]
	do
		if [[ $1 == "--" ]]
		then
			arg_parse_ignore=true
			shift
			continue
		fi
		if [[ $arg_parse_ignore == true ]]
		then
			ignore_args+=("--ignore='$1'")
		else
			search_args+=("$1")
		fi
		shift
	done
	if [ ${#search_args[@]} -eq 0 ]
	then
		echo "Error: No query. What do you want to search for?"
		return
	fi
	local search_dirs=("$HOME/workspace" "$HOME/Downloads" "$HOME/Documents" "$HOME/.scripts")
	local search_command="ag --nogroup --color"
	for i in "${ignore_args[@]}"
	do
		search_command+=" $i"
	done
	search_command+=" '${search_args[@]}' ${search_dirs[@]}"
	echo "Running command: $search_command"
	local out=$(eval $search_command | fzf --ansi --delimiter=':' --with-nth=1,2 --preview="bat --color=always --style=numbers,grid --highlight-line {2} --paging=always --pager 'less +{2}' {1}" --preview-window=right:50%:nowrap)
	if [[ -n "$out" ]]
	then
		local file=$(echo "$out" | cut -d':' -f1)
		local line=$(echo "$out" | cut -d':' -f2)
		echo "Opening $file at line $line..."

		# Determine the two-level parent workspace directory manually
		local workspace_dir=$(dirname "$file" | sed -E 's|^('$HOME'/workspace/[^/]+/[^/]+).*$|\1|')

		# If workspace is already open for this directory, add to the workspace
		local is_workspace_open=$(ps aux | grep "code.*$workspace_dir" | grep -v grep)
		if [[ -n "$is_workspace_open" ]]
		then
			# Add the file to the already opened workspace
			code --add "$file" --goto "$file:$line"
		else
			# Open a new workspace window for the specific workspace directory
			code "$workspace_dir" --goto "$file:$line"
		fi
	else
		echo "No file selected."
	fi
}

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

About

addons to my vim and zsh

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages