- 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,5 +1,9 @@
#!/bin/sh #!/bin/sh
# #
# TODO: Use this to better manage dotfiles
# https://github.com/dylanirlbeck/dotfiles/blob/master/scripts/bootstrap.sh
################################## ##################################
# Parse script arguments # Parse script arguments
################################## ##################################
@@ -8,29 +12,6 @@
QUIET="n" QUIET="n"
CREATE_LINKS="n" CREATE_LINKS="n"
while [[ "${#}" -gt 0 ]]; do
case $1 in
-q | --quiet)
QUIET="y"
shift
;;
-l | --create-links)
CREATE_LINKS="y"
shift
;;
-h | --help)
echo
usage
echo
exit 0
;;
*)
usage "Unknown parameter passed: $1" "h"
exit 1
;;
esac
done
usage() { usage() {
if [ -n "$1" ]; then if [ -n "$1" ]; then
echo "" echo ""
@@ -57,32 +38,61 @@ place_dotfile_at_target_location() {
# To avoid over writing existing dot file, we rename them # To avoid over writing existing dot file, we rename them
# Appending the timestamp to file name # Appending the timestamp to file name
if [[ -f "${file_target_location}" || -L "${file_target_location}" ]]; then if [ -f "${file_target_location}" ] || [ -L "${file_target_location}" ]; then
# echo "mv ${file_target_location} ${file_target_location}_${TS}" && [[ "$QUIET" == "n" ]] && echo "Existing dotfile renamed to ${file_target_location}_${TS}" # echo "mv ${file_target_location} ${file_target_location}_${TS}" && [[ "$QUIET" == "n" ]] && echo "Existing dotfile renamed to ${file_target_location}_${TS}"
mv "${file_target_location}" "${file_target_location}_${TS}" && [[ "$QUIET" == "n" ]] && echo "Existing setting renamed to ${file_target_location}_${TS}" mv "${file_target_location}" "${file_target_location}_${TS}" && [ "$QUIET" = "n" ] && echo "Existing setting renamed to ${file_target_location}_${TS}"
fi fi
local target_directory local target_directory
target_directory=$(dirname "${file_target_location}") target_directory=$(dirname "${file_target_location}")
if [[ ! -d "${target_directory}" ]]; then if [ ! -d "${target_directory}" ]; then
mkdir -p "${target_directory}" && [[ "$QUIET" == "n" ]] && echo "Directory ${target_directory} created" mkdir -p "${target_directory}" && [ "$QUIET" = "n" ] && echo "Directory ${target_directory} created"
fi fi
if [[ "$CREATE_LINKS" == "y" ]]; then if [ "$CREATE_LINKS" = "y" ]; then
# echo "ln -s ${source_file_location} ${target_directory}" # echo "ln -s ${source_file_location} ${target_directory}"
ln -s "${source_file_location}" "${target_directory}" && [[ "$QUIET" == "n" ]] && echo "Linked ${file_target_location}" ln -s "${source_file_location}" "${target_directory}" && [ "$QUIET" = "n" ] && echo "Linked ${file_target_location}"
else else
# echo "cp ${source_file_location} ${target_directory}" # echo "cp ${source_file_location} ${target_directory}"
cp "${source_file_location}" "${target_directory}" && [[ "$QUIET" == "n" ]] && echo "Copied ${file_target_location}" cp "${source_file_location}" "${target_directory}" && [ "$QUIET" = "n" ] && echo "Copied ${file_target_location}"
fi fi
} }
main() { main() {
if [[ $(uname -s) == *Darwin* ]]; then while [ "${#}" -gt 0 ]; do
case $1 in
-q | --quiet)
QUIET="y"
shift
;;
-l | --create-links)
CREATE_LINKS="y"
shift
;;
-h | --help)
echo
usage
echo
exit 0
;;
*)
usage "Unknown parameter passed: $1" "h"
exit 1
;;
esac
done
case $(uname -a) in
Linux*)
OS="linux"
[ "$XDG_CURRENT_DESKTOP" = "KDE" ] && OS="kde-neon"
;;
Darwin*)
OS="macos" OS="macos"
else ;;
OS="kde-neon" *)
fi OS="UNSUPPORTED"
esac
TS=$(date '+%d_%m_%Y-%H_%M_%S') TS=$(date '+%d_%m_%Y-%H_%M_%S')
@@ -91,19 +101,19 @@ main() {
# Copy all files in "Common" dotfiles to $HOME directory ("~") # Copy all files in "Common" dotfiles to $HOME directory ("~")
find "./common" -type f ! -path '*.DS_Store' ! -path '*.directory' -print0 | while IFS= read -r -d '' file; find "./common" -type f ! -path '*.DS_Store' ! -path '*.directory' -print0 | while IFS= read -r -d '' file;
do do
local file_target_location="${file/.\/common/$HOME}" local file_target_location="${file/.\/common/$HOME}"
local source_file_location="${file/./$PWD}" local source_file_location="${file/./$PWD}"
place_dotfile_at_target_location "$source_file_location" "$file_target_location" "$TS" place_dotfile_at_target_location "$source_file_location" "$file_target_location" "$TS"
done done
# Copy platform specific files to $HOME directory ("~") # Copy platform specific files to $HOME directory ("~")
find "./${OS}" -type f ! -path '*.DS_Store' ! -path '*.directory' -print0 | while IFS= read -r -d '' file; find "./${OS}" -type f ! -path '*.DS_Store' ! -path '*.directory' -print0 | while IFS= read -r -d '' file;
do do
local file_target_location="${file/.\/${OS}/$HOME}" local file_target_location="${file/.\/${OS}/$HOME}"
local source_file_location="${file/./$PWD}" local source_file_location="${file/./$PWD}"
place_dotfile_at_target_location "$source_file_location" "$file_target_location" "$TS" place_dotfile_at_target_location "$source_file_location" "$file_target_location" "$TS"
done done
} }
main "$@" main "$@"

View File

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

View File

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

View File

@@ -1,5 +1,11 @@
# vim:fileencoding=utf-8:foldmethod=marker # 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 {{{ #: Fonts {{{
#: kitty has very powerful font management. You can configure #: kitty has very powerful font management. You can configure
@@ -422,10 +428,21 @@ cursor_beam_thickness 1
#: }}} #: }}}
scrollback_lines 10000 scrollback_lines 100000
scrollback_pager_history_size 10 scrollback_pager_history_size 100000
scrollback_pager nvim -c 'set ft=man' 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 {{{
# mouse_hide_wait 3.0 # 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 {{{ #: Color scheme {{{
@@ -1656,15 +1673,6 @@ background_blur 65
update_check_interval 0 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 {{{ #: OS specific tweaks {{{
# wayland_titlebar_color system # wayland_titlebar_color system

File diff suppressed because it is too large Load Diff

View File

@@ -1,11 +1,8 @@
#!/bin/sh #!/bin/sh
# Generic # Generic
alias sb="source ~/.bashrc"
alias bashreload="source ~/.bashrc" alias bashreload="source ~/.bashrc"
alias sz="source ~/.zshrc"
alias zshreload="source ~/.zshrc" alias zshreload="source ~/.zshrc"
alias zshrc="${EDITOR} ~/.zshrc"
alias free="free -ht" alias free="free -ht"
alias type="type -a" alias type="type -a"
alias grep='grep --color=auto' alias grep='grep --color=auto'
@@ -16,7 +13,7 @@ alias untar='tar -zxvf '
alias wget="wget --hsts-file ${WGET_HSTS_FILE}" alias wget="wget --hsts-file ${WGET_HSTS_FILE}"
alias v="${EDITOR}" alias v="${EDITOR}"
alias snvim="${HOMEBREW_PREFIX}"/bin/nvim # Stable nvim alias snvim="${HOMEBREW_PREFIX}/bin/nvim" # Stable nvim
url_encode(){ url_encode(){
python3 -c "import urllib.parse, sys; print(urllib.parse.quote(sys.stdin.read()))" <<< "$1" 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 ../../../' # Go back 3 directory levels
alias cd_root='cd $(git rev-parse --show-toplevel 2>/dev/null || echo ".")' alias cd_root='cd $(git rev-parse --show-toplevel 2>/dev/null || echo ".")'
alias cd_git_root=cd_root alias cd_git_root=cd_root
alias c=clear
alias cl=clear alias cl=clear
alias lsc='ls --color=auto --hyperlink=auto' alias lsc='ls --color=auto --hyperlink=auto'
alias ll='lsc -alhF' alias ll='lsc -alhF'
@@ -49,7 +45,6 @@ mkcd () {
cd "$1" || exit cd "$1" || exit
} }
# Network # Network
alias ping="ping -c 10" alias ping="ping -c 10"
alias ping8="ping 8.8.8.8" alias ping8="ping 8.8.8.8"
@@ -57,18 +52,17 @@ alias ping1="ping 1.1.1.1"
alias p8="ping8" alias p8="ping8"
alias p1="ping1" alias p1="ping1"
alias pubip="curl https://ipinfo.io/ip; echo" alias pubip="curl https://ipinfo.io/ip; echo"
alias speedtest="speedtest-cli --secure" # needs speedtest-cli installed alias speedtest="speedtest-cli --secure"
geoip () { 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 # 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_push_all_changes(){
git add . && git commit -am "${1}" && git push git add . && git commit -am "${1}" && git push
} }
alias git_just_push=git_push_all_changes
alias ta="tmux a" alias ta="tmux a"
@@ -83,11 +77,24 @@ alias OldConfig="NVIM_APPNAME=oldconfig nvim"
nvims() { nvims() {
items=$(find -L "$HOME"/.config -maxdepth 2 -name "init.lua" -type f -execdir sh -c 'pwd | xargs basename' \;) 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) 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" echo "Nothing selected"
return 0 return 0
elif [[ $config == "default" ]]; then elif [ "$config" = "default" ]; then
config="" config=""
fi 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" [ ! -d "$HOME/bin" ] || PATH="$HOME/bin:$PATH"
# set PATH so it includes user's private bin if it exists # 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 # Set the config directory environment variable
[ ! -z "$XDG_CONFIG_HOME" ] || export XDG_CONFIG_HOME="$HOME/.config" [ -n "$XDG_CONFIG_HOME" ] || export XDG_CONFIG_HOME="$HOME/.config"
# Set the cache directory enviroment variable # Set the cache directory environment variable
[ ! -z "$XDG_CACHE_HOME" ] || export XDG_CACHE_HOME="$HOME/.cache" [ -n "$XDG_CACHE_HOME" ] || export XDG_CACHE_HOME="$HOME/.cache"
# Set the data directory enviroment variable # Set the data directory environment variable
[ ! -z "$XDG_DATA_HOME" ] || export XDG_DATA_HOME="$HOME/.local/share" [ -n "$XDG_DATA_HOME" ] || export XDG_DATA_HOME="$HOME/.local/share"
# Set the state directory enviroment variable # Set the state directory environment variable
[ ! -z "$XDG_STATE_HOME" ] || export XDG_STATE_HOME="$HOME/.local/state" [ -n "$XDG_STATE_HOME" ] || export XDG_STATE_HOME="$HOME/.local/state"
################################################################################## ##################################################################################
@@ -24,7 +28,8 @@ eval "$(ssh-agent -s)" >/dev/null
ulimit -n 10240 ulimit -n 10240
EDITOR=$(command -v nvim 2>/dev/null || command -v vim 2>/dev/null) 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 # Manually follow steps from https://steamcommunity.com/app/646570/discussions/1/3935537639868400686
# To disable ~/.oracle_jre_usage/ from being created # 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" [ ! -f "$XDG_CONFIG_HOME/shell/aliases_personal" ] || source "$XDG_CONFIG_HOME/shell/aliases_personal"
if [ "$(uname -s)" = "Linux" ]; then 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" export __GL_SHADER_DISK_CACHE_PATH="$XDG_CACHE_HOME/nvidia"
# Needs upstream fix to work: https://bugs.kde.org/show_bug.cgi?id=415770 # 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 GTK2_RC_FILES="$XDG_CONFIG_HOME/gtk-2.0/gtkrc-2.0"
export CUDA_CACHE_PATH="XDG_CACHE_HOME/nv" export CUDA_CACHE_PATH="XDG_CACHE_HOME/nv"
# Map caps-lock to escape TIP: also added to /etc/profile
setxkbmap -option caps:escape
fi fi
export QT_PLUGIN_PATH="$HOME/local/lib/qt/plugins/:"
if [ "$XDG_SESSION_DESKTOP" = "KDE" ]; then if [ "$XDG_SESSION_DESKTOP" = "KDE" ]; then
export KDEHOME="$XDG_CONFIG_HOME/KDE" export KDEHOME="$XDG_CONFIG_HOME/KDE"
fi fi
@@ -71,9 +80,10 @@ export SCCACHE_CACHE_SIZE="20G"
# Setup DotNet # Setup DotNet
export DOTNET_CLI_TELEMETRY_OPTOUT=1 export DOTNET_CLI_TELEMETRY_OPTOUT=1
export DOTNET_CLI_HOME="$XDG_CONFIG_HOME/dotnet" export DOTNET_CLI_HOME="$XDG_CONFIG_HOME/dotnet"
export DOTNET_TOOLS_PATH="$XDG_DATA_HOME/dotnet"
# Cause we need it available on login # FIX: BELOW DID NOT WORK
alias code="code --extensions-dir $XDG_DATA_HOME/vscode" # alias code="code --extensions-dir $XDG_DATA_HOME/vscode"
# Java # Java
export _JAVA_OPTIONS=-Djava.util.prefs.userRoot="$XDG_CONFIG_HOME/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 # Setup Node & n
export NPM_CONFIG_USERCONFIG="$XDG_CONFIG_HOME/node/npmrc" export NPM_CONFIG_USERCONFIG="$XDG_CONFIG_HOME/node/npmrc"
export NODE_REPL_HISTORY="$XDG_CONFIG_HOME/node/node_repl_history" 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 PATH="$N_PREFIX/bin:$PATH"
export AWS_CONFIG_FILE="$XDG_CONFIG_HOME/aws/config" export AWS_CONFIG_FILE="$XDG_CONFIG_HOME/aws/config"
export AWS_SHARED_CREDENTIALS_FILE="$XDG_CONFIG_HOME/aws/credentials" export AWS_SHARED_CREDENTIALS_FILE="$XDG_CONFIG_HOME/aws/credentials"
export DOCKER_CONFIG="$XDG_CONFIG_HOME/docker" 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 # 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. # Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc.
# Initialization code that may require console input (password prompts, [y/n] # 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" HISTORY_BASE="$XDG_STATE_HOME/shell/per-directory-history"
# NOTE: Should be exported before sourcing oh-my-zsh, to avoid the dumpfiles on $HOME # 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` # To customize prompt, run `p10k configure`
[[ ! -f "$XDG_CONFIG_HOME/shell/p10k.zsh" ]] || source "$XDG_CONFIG_HOME/shell/p10k.zsh" [[ ! -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 # enable vi-mode
bindkey -v bindkey -v
# Basic auto/tab completions # Add brew provided autocompletions to path
autoload -U compinit [[ ! -d "/home/linuxbrew/.linuxbrew/share/zsh/site-functions" ]] || FPATH="/home/linuxbrew/.linuxbrew/share/zsh/site-functions:$FPATH"
zstyle ':completion:*' menu select cache-path "$XDG_CACHE_HOME/zsh/zcompcache" # Auto/tab completions
autoload -Uz compinit
zstyle ':completion::complete:*' gain-privileges 1 menu select cache-path "$XDG_CACHE_HOME/zsh/zcompcache"
zmodload zsh/complist zmodload zsh/complist
compinit -d "$XDG_CACHE_HOME/zsh/zcompdump-$ZSH_VERSION" compinit -d "$XDG_CACHE_HOME/zsh/zcompdump-$ZSH_VERSION"
_comp_options+=(globdots) # Include hidden files _comp_options+=(globdots) # Include hidden files
@@ -101,17 +103,7 @@ _comp_options+=(globdots) # Include hidden files
# [ctrl+r]:replaces shell command search # [ctrl+r]:replaces shell command search
# [ctrl+t]:fzf & over the files & directories under the current one & paste it to prompt # [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 # [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 [ -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
command -v zoxide >/dev/null && eval "$(zoxide init zsh)" command -v zoxide >/dev/null && eval "$(zoxide init zsh)"
command -v zoxide >/dev/null && bindkey -s '^o' 'op\n' # Fuzzyfind projects and open in nvim
# 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

View File

@@ -3,7 +3,7 @@
# Directories and Directory listings # Directories and Directory listings
dir_size(){ dir_size(){
local dir local dir
if [[ -z "$1" ]]; then if [ -z "$1" ]; then
dir="${PWD}" dir="${PWD}"
else else
dir="$1" dir="$1"
@@ -11,6 +11,7 @@ dir_size(){
du -ah "${dir}" --max-depth=1 | sort -hr du -ah "${dir}" --max-depth=1 | sort -hr
} }
alias tldr="tldr --platform=linux "
# Network # Network
@@ -23,7 +24,7 @@ alias listening_apps="sudo netstat -nutlp | grep ':' | awk '{print \$1,\$4,\$NF}
# Update & Upgrades # Update & Upgrades
alias up="sudo pkcon refresh && sudo pkcon update && sudo apt dist-upgrade && sudo apt autoremove && rustup update && brew upgrade && brew autoremove && npm update -g" alias up="sudo pkcon refresh && sudo pkcon update && sudo apt dist-upgrade && sudo apt autoremove && rustup update && brew upgrade && brew autoremove && brew cleanup && npm update -g"
alias distup="sudo apt dist-upgrade" alias distup="sudo apt dist-upgrade"
alias autorem="sudo apt autoremove" alias autorem="sudo apt autoremove"
alias update="sudo apt-get update" alias update="sudo apt-get update"
@@ -44,7 +45,7 @@ alias fpmreset74="sudo systemctl restart php7.4-fpm"
f2b_banned_ips() { f2b_banned_ips() {
local provided_jail=$1 local provided_jail=$1
if [[ -n "${provided_jail// /}" ]]; then if [ -n "${provided_jail// /}" ]; then
for ip in $(sudo fail2ban-client status "${provided_jail}" | tail -1 | sed 's/[^:]*://;s/\s*//') for ip in $(sudo fail2ban-client status "${provided_jail}" | tail -1 | sed 's/[^:]*://;s/\s*//')
do do
printf "%17s\n" "$ip" printf "%17s\n" "$ip"
@@ -56,7 +57,7 @@ f2b_banned_ips() {
local banned_ip_count local banned_ip_count
banned_ip_count=$(sudo fail2ban-client status "${JAIL}" | grep -oP 'Currently banned:\s*\K\d+') banned_ip_count=$(sudo fail2ban-client status "${JAIL}" | grep -oP 'Currently banned:\s*\K\d+')
if [[ "${banned_ip_count}" -gt 0 ]]; then if [ "${banned_ip_count}" -gt 0 ]; then
echo "${JAIL}: ${banned_ip_count}" echo "${JAIL}: ${banned_ip_count}"
for ip in $(sudo fail2ban-client status "${JAIL}" | tail -1 | sed 's/[^:]*://;s/\s*//') for ip in $(sudo fail2ban-client status "${JAIL}" | tail -1 | sed 's/[^:]*://;s/\s*//')
@@ -81,7 +82,7 @@ f2b_unban_ip() {
local jail="$2" local jail="$2"
# If jail is provided - use that jail to directly unban # If jail is provided - use that jail to directly unban
if [[ -n "${jail// /}" ]]; then if [ -n "${jail// /}" ]; then
sudo fail2ban-client set "${jail}" unbanip "${ip_to_unban}" > /dev/null && echo "Successfully released ban" sudo fail2ban-client set "${jail}" unbanip "${ip_to_unban}" > /dev/null && echo "Successfully released ban"
else else
# Find all JAILS this IP belong to # Find all JAILS this IP belong to
@@ -91,7 +92,7 @@ f2b_unban_ip() {
do do
local banned_ip_count local banned_ip_count
banned_ip_count=$(sudo fail2ban-client status "${JAIL}" | grep -oP 'Currently banned:\s*\K\d+') banned_ip_count=$(sudo fail2ban-client status "${JAIL}" | grep -oP 'Currently banned:\s*\K\d+')
if [[ "$banned_ip_count" -gt 0 ]] && [[ $(sudo fail2ban-client status "${JAIL}") == *"${ip_to_unban}"* ]]; then if [ "$banned_ip_count" -gt 0 ] && [[ $(sudo fail2ban-client status "${JAIL}") == *"${ip_to_unban}"* ]]; then
local found_ip="true" local found_ip="true"
echo "Unbanning from ${JAIL}:" echo "Unbanning from ${JAIL}:"
sudo fail2ban-client set "${JAIL}" unbanip "${ip_to_unban}" > /dev/null && echo "Successfully released ban" sudo fail2ban-client set "${JAIL}" unbanip "${ip_to_unban}" > /dev/null && echo "Successfully released ban"

View File

@@ -3,7 +3,7 @@
# Directories and Directory listings # Directories and Directory listings
dir_size() { dir_size() {
local dir local dir
if [[ -z "$1" ]]; then if [ -z "$1" ]; then
dir="${PWD}" dir="${PWD}"
else else
dir="$1" dir="$1"
@@ -13,4 +13,4 @@ dir_size() {
} }
# Update & Upgrades # Update & Upgrades
alias up="brew upgrade --cask && brew upgrade --formula && brew autoremove && rustup update && npm update -g" alias up="brew upgrade --cask && brew upgrade --formula && brew autoremove && brew cleanup && rustup update && npm update -g"