- Shell Scripts: FZF function to fuzzy find all of my projects and open nvim on that project

- Shell Scripts: WIP efforts to comply all to POSIX
This commit is contained in:
Pratik Tripathy
2024-02-06 23:17:01 +05:30
parent 5fa524dd1d
commit 6b2d076cdc
10 changed files with 146 additions and 2636 deletions

View File

@@ -1,6 +1,7 @@
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
[ ! -f "$HOME/.profile" ] || source "$HOME/.profile"
# If not running interactively, don't do anything
case $- in

View File

@@ -8,7 +8,7 @@
"extensions.ignoreRecommendations": true,
// Editor
"editor.fontSize": 20, // Reduces the Activity Bar size
"editor.fontSize": 21, // Reduces the Activity Bar size
"editor.cursorWidth": 4,
"editor.minimap.enabled": false,
"editor.wordWrap": "on",
@@ -208,7 +208,7 @@
"python.jediEnabled": false,
"python.languageServer": "Pylance",
"workbench.iconTheme": "material-icon-theme",
"workbench.colorTheme": "GitHub Dark",
"workbench.colorTheme": "GitHub Dark Dimmed",
// Rust
// "rust.build_on_save": true,

View File

@@ -1,5 +1,11 @@
# vim:fileencoding=utf-8:foldmethod=marker
# TODO:
# - Display current directory on OS title: even when nvim or any other forground app is running
# - Vim keymaps <ctrl>+hjkl to move around splits: https://github.com/knubie/vim-kitty-navigator
# - OR <ctrl+shift>+ <arrow_keys>??? in sync with konsole???
# - <Ctrl+shift> [/] to decrease/increase split size
#: Fonts {{{
#: kitty has very powerful font management. You can configure
@@ -422,10 +428,21 @@ cursor_beam_thickness 1
#: }}}
scrollback_lines 10000
scrollback_pager_history_size 10
scrollback_lines 100000
scrollback_pager_history_size 100000
scrollback_pager nvim -c 'set ft=man'
# Enable kitty scrollback.nvim plugin
allow_remote_control yes
listen_on unix:/tmp/kitty
shell_integration enabled no-sudo no-complete
action_alias kitty_scrollback_nvim kitten /home/pratik/.local/share/nvim/lazy/kitty-scrollback.nvim/python/kitty_scrollback_nvim.py --nvim-args --clean --noplugin -n
map kitty_mod+h kitty_scrollback_nvim
map kitty_mod+g kitty_scrollback_nvim --config ksb_builtin_last_cmd_output
mouse_map kitty_mod+right press ungrabbed combine : mouse_select_command_output : kitty_scrollback_nvim --config ksb_builtin_last_cmd_output
map kitty_mod+f7 show_kitty_env_vars
#: Mouse {{{
# mouse_hide_wait 3.0
@@ -1184,7 +1201,7 @@ map ctrl+shift+o launch --cwd=current --type=tab nvim
#: }}}
tab_title_template "{sup.index}{fmt.fg.red}{bell_symbol}{activity_symbol}{fmt.fg.tab}{title[title.rfind('/')+1:]} : {tab.active_exe}"
tab_title_template "{fmt.fg.red}{bell_symbol}{activity_symbol}{fmt.fg.tab}{title[title.rfind('/')+1:]} : {tab.active_exe}{sup.index}"
#: Color scheme {{{
@@ -1656,15 +1673,6 @@ background_blur 65
update_check_interval 0
# Enable kitty scrollback.nvim plugin
allow_remote_control yes
listen_on unix:/tmp/kitty
shell_integration enabled
action_alias kitty_scrollback_nvim kitten /home/pratik/.local/share/nvim/lazy/kitty-scrollback.nvim/python/kitty_scrollback_nvim.py
map kitty_mod+h kitty_scrollback_nvim
map kitty_mod+g kitty_scrollback_nvim --config ksb_builtin_last_cmd_output
mouse_map kitty_mod+right press ungrabbed combine : mouse_select_command_output : kitty_scrollback_nvim --config ksb_builtin_last_cmd_output
#: OS specific tweaks {{{
# wayland_titlebar_color system

File diff suppressed because it is too large Load Diff

View File

@@ -1,11 +1,8 @@
#!/bin/sh
# Generic
alias sb="source ~/.bashrc"
alias bashreload="source ~/.bashrc"
alias sz="source ~/.zshrc"
alias zshreload="source ~/.zshrc"
alias zshrc="${EDITOR} ~/.zshrc"
alias free="free -ht"
alias type="type -a"
alias grep='grep --color=auto'
@@ -16,7 +13,7 @@ alias untar='tar -zxvf '
alias wget="wget --hsts-file ${WGET_HSTS_FILE}"
alias v="${EDITOR}"
alias snvim="${HOMEBREW_PREFIX}"/bin/nvim # Stable nvim
alias snvim="${HOMEBREW_PREFIX}/bin/nvim" # Stable nvim
url_encode(){
python3 -c "import urllib.parse, sys; print(urllib.parse.quote(sys.stdin.read()))" <<< "$1"
@@ -35,7 +32,6 @@ alias ..="cd .."
alias ...='cd ../../../' # Go back 3 directory levels
alias cd_root='cd $(git rev-parse --show-toplevel 2>/dev/null || echo ".")'
alias cd_git_root=cd_root
alias c=clear
alias cl=clear
alias lsc='ls --color=auto --hyperlink=auto'
alias ll='lsc -alhF'
@@ -49,7 +45,6 @@ mkcd () {
cd "$1" || exit
}
# Network
alias ping="ping -c 10"
alias ping8="ping 8.8.8.8"
@@ -57,18 +52,17 @@ alias ping1="ping 1.1.1.1"
alias p8="ping8"
alias p1="ping1"
alias pubip="curl https://ipinfo.io/ip; echo"
alias speedtest="speedtest-cli --secure" # needs speedtest-cli installed
alias speedtest="speedtest-cli --secure"
geoip () {
curl -s https://ipinfo.io | sed '/readme/d;/loc/d;/postal/d;s/org/ISP/' | tr -d {},\" | awk -F ':' 'NF {printf ("%10s: %.25s \n", $1, $2)}'
curl -s https://ipinfo.io | sed '/readme\|loc\|postal\|{\|}\|hostname/d;s/org/ISP/;s/"\|,$//g' | awk -F ':' 'NF { printf("%10s: %s \n", $1, $2)}'
}
# Git
# To use this - Ensure all git server SSH are in ~/.ssh
alias git_signin='(for i in ~/.ssh/{*github*,*gitea*}; do ssh-add -k $i; done; ) && (echo; echo Identities added successfully)'
git_push_all_changes(){
git add . && git commit -am "${1}" && git push
}
alias git_just_push=git_push_all_changes
alias ta="tmux a"
@@ -83,11 +77,24 @@ alias OldConfig="NVIM_APPNAME=oldconfig nvim"
nvims() {
items=$(find -L "$HOME"/.config -maxdepth 2 -name "init.lua" -type f -execdir sh -c 'pwd | xargs basename' \;)
config=$(printf "%s\n" "${items[@]}" | fzf --prompt=" Neovim Config  " --height=~50% --layout=reverse --border --exit-0)
if [[ -z $config ]]; then
if [ -z "$config" ]; then
echo "Nothing selected"
return 0
elif [[ $config == "default" ]]; then
elif [ "$config" = "default" ]; then
config=""
fi
NVIM_APPNAME=$config nvim $@
NVIM_APPNAME=$config nvim "$@"
}
op() {
local chosen_project
chosen_project="$(find -L ~/Code -mindepth 2 -maxdepth 2 -not -path '*/.*' -printf "%T@ %p\n" | sort -nr | cut -d ' ' -f 2- | fzf --border --layout=reverse --height=~50% --prompt='Select a project: ' --preview 'ls -Lltc {1}')"
if [ -z "$chosen_project" ]; then
return 0
fi
cd "$chosen_project" || return
nvim
}
# TODO: Create fuzzy finder for cht.sh & tldr

View File

@@ -4,19 +4,23 @@
[ ! -d "$HOME/bin" ] || PATH="$HOME/bin:$PATH"
# set PATH so it includes user's private bin if it exists
[ ! -d "$HOME/.local/bin" ] || PATH="$HOME/.local/bin:$PATH"
# HACK: Appended to end of $PATH instead of beginning
# Kitty can't seem to locate nvim when .local/bin is path-ed earlier
# With this, Kitty finds the unstable nvim from ~/.local/bin (for scroll_back buffer selection)
# And I use the brew version of nvim for my work
[ ! -d "$HOME/.local/bin" ] || PATH="$PATH:$HOME/.local/bin"
# Set the config directory enviroment variable
[ ! -z "$XDG_CONFIG_HOME" ] || export XDG_CONFIG_HOME="$HOME/.config"
# Set the config directory environment variable
[ -n "$XDG_CONFIG_HOME" ] || export XDG_CONFIG_HOME="$HOME/.config"
# Set the cache directory enviroment variable
[ ! -z "$XDG_CACHE_HOME" ] || export XDG_CACHE_HOME="$HOME/.cache"
# Set the cache directory environment variable
[ -n "$XDG_CACHE_HOME" ] || export XDG_CACHE_HOME="$HOME/.cache"
# Set the data directory enviroment variable
[ ! -z "$XDG_DATA_HOME" ] || export XDG_DATA_HOME="$HOME/.local/share"
# Set the data directory environment variable
[ -n "$XDG_DATA_HOME" ] || export XDG_DATA_HOME="$HOME/.local/share"
# Set the state directory enviroment variable
[ ! -z "$XDG_STATE_HOME" ] || export XDG_STATE_HOME="$HOME/.local/state"
# Set the state directory environment variable
[ -n "$XDG_STATE_HOME" ] || export XDG_STATE_HOME="$HOME/.local/state"
##################################################################################
@@ -24,7 +28,8 @@ eval "$(ssh-agent -s)" >/dev/null
ulimit -n 10240
EDITOR=$(command -v nvim 2>/dev/null || command -v vim 2>/dev/null)
VISUAL=$EDITOR
export EDITOR
export VISUAL=$EDITOR
# Manually follow steps from https://steamcommunity.com/app/646570/discussions/1/3935537639868400686
# To disable ~/.oracle_jre_usage/ from being created
@@ -36,14 +41,18 @@ VISUAL=$EDITOR
[ ! -f "$XDG_CONFIG_HOME/shell/aliases_personal" ] || source "$XDG_CONFIG_HOME/shell/aliases_personal"
if [ "$(uname -s)" = "Linux" ]; then
export QT_PLUGIN_PATH="~/.local/lib/qt/plugins/:" # TODO: Mac as well?
export __GL_SHADER_DISK_CACHE_PATH="$XDG_CACHE_HOME/nvidia"
# Needs upstream fix to work: https://bugs.kde.org/show_bug.cgi?id=415770
export GTK2_RC_FILES="$XDG_CONFIG_HOME/gtk-2.0/gtkrc-2.0"
export CUDA_CACHE_PATH="XDG_CACHE_HOME/nv"
# Map caps-lock to escape TIP: also added to /etc/profile
setxkbmap -option caps:escape
fi
export QT_PLUGIN_PATH="$HOME/local/lib/qt/plugins/:"
if [ "$XDG_SESSION_DESKTOP" = "KDE" ]; then
export KDEHOME="$XDG_CONFIG_HOME/KDE"
fi
@@ -71,9 +80,10 @@ export SCCACHE_CACHE_SIZE="20G"
# Setup DotNet
export DOTNET_CLI_TELEMETRY_OPTOUT=1
export DOTNET_CLI_HOME="$XDG_CONFIG_HOME/dotnet"
export DOTNET_TOOLS_PATH="$XDG_DATA_HOME/dotnet"
# Cause we need it available on login
alias code="code --extensions-dir $XDG_DATA_HOME/vscode"
# FIX: BELOW DID NOT WORK
# alias code="code --extensions-dir $XDG_DATA_HOME/vscode"
# Java
export _JAVA_OPTIONS=-Djava.util.prefs.userRoot="$XDG_CONFIG_HOME/java"
@@ -81,10 +91,15 @@ export _JAVA_OPTIONS=-Djava.util.prefs.userRoot="$XDG_CONFIG_HOME/java"
# Setup Node & n
export NPM_CONFIG_USERCONFIG="$XDG_CONFIG_HOME/node/npmrc"
export NODE_REPL_HISTORY="$XDG_CONFIG_HOME/node/node_repl_history"
export N_PREFIX="$XDG_DATA_HOME/nvm" # "n" would be confusing
export N_PREFIX="$XDG_DATA_HOME/n_node"
export PATH="$N_PREFIX/bin:$PATH"
export AWS_CONFIG_FILE="$XDG_CONFIG_HOME/aws/config"
export AWS_SHARED_CREDENTIALS_FILE="$XDG_CONFIG_HOME/aws/credentials"
export DOCKER_CONFIG="$XDG_CONFIG_HOME/docker"
export FZF_DEFAULT_COMMAND='rg --files --hidden'
export FZF_DEFAULT_OPTS='--layout=reverse --inline-info --height=~50% --border'
export TLDR_CACHE_DIR="$XDG_CACHE_HOME/tldr"

View File

@@ -1,5 +1,5 @@
# I'm not using a separate .zprofile; reuse the .profile instead
[ ! -f "$HOME/.profile" ] || source "$HOME/.profile"
[[ ! -f "$HOME/.profile" ]] || source "$HOME/.profile"
# Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc.
# Initialization code that may require console input (password prompts, [y/n]
@@ -66,9 +66,9 @@ VI_MODE_CURSOR_INSERT=3
HISTORY_BASE="$XDG_STATE_HOME/shell/per-directory-history"
# NOTE: Should be exported before sourcing oh-my-zsh, to avoid the dumpfiles on $HOME
export ZSH_COMPDUMP=$XDG_CACHE_HOME/zsh/zcompdump-$HOST
export ZSH_COMPDUMP="$XDG_CACHE_HOME/zsh/zcompdump-$HOST"
source $ZSH/oh-my-zsh.sh
source "$ZSH/oh-my-zsh.sh"
# To customize prompt, run `p10k configure`
[[ ! -f "$XDG_CONFIG_HOME/shell/p10k.zsh" ]] || source "$XDG_CONFIG_HOME/shell/p10k.zsh"
@@ -91,9 +91,11 @@ setopt HIST_IGNORE_SPACE # Don't add commands that start with whitespac
# enable vi-mode
bindkey -v
# Basic auto/tab completions
autoload -U compinit
zstyle ':completion:*' menu select cache-path "$XDG_CACHE_HOME/zsh/zcompcache"
# Add brew provided autocompletions to path
[[ ! -d "/home/linuxbrew/.linuxbrew/share/zsh/site-functions" ]] || FPATH="/home/linuxbrew/.linuxbrew/share/zsh/site-functions:$FPATH"
# Auto/tab completions
autoload -Uz compinit
zstyle ':completion::complete:*' gain-privileges 1 menu select cache-path "$XDG_CACHE_HOME/zsh/zcompcache"
zmodload zsh/complist
compinit -d "$XDG_CACHE_HOME/zsh/zcompdump-$ZSH_VERSION"
_comp_options+=(globdots) # Include hidden files
@@ -101,17 +103,7 @@ _comp_options+=(globdots) # Include hidden files
# [ctrl+r]:replaces shell command search
# [ctrl+t]:fzf & over the files & directories under the current one & paste it to prompt
# [alt+c] :fzf & cd into a directory under the current one
[ -f $XDG_STATE_HOME/shell/fzf.zsh ] && source $XDG_STATE_HOME/shell/fzf.zsh
# FPATH="$FPATH:$HOMEBREW_PREFIX/share/zsh/site-functions" # TODO: Make the completions here work
[ -f "$XDG_STATE_HOME/shell/fzf.zsh" ] && source "$XDG_STATE_HOME/shell/fzf.zsh"
command -v zoxide >/dev/null && eval "$(zoxide init zsh)"
# TODO: Use fzf + fd + kitty to auto create kitty sessions: use only the following directories
# 1. /media/pratik/Office/Code/
# 2. /media/pratik/Projects/LearningProjects/
# 3. /media/pratik/Projects/PersonalProjects/
# 4. /media/pratik/Projects/Interviews/
# - Ignore hidden directories
# - Put it in one of the aliases
command -v zoxide >/dev/null && bindkey -s '^o' 'op\n' # Fuzzyfind projects and open in nvim