Skip to content

Instantly share code, notes, and snippets.

@illescasDaniel
Created April 16, 2024 14:16
Show Gist options
  • Save illescasDaniel/b6e07046e0a24bda34b1b98ae2a03823 to your computer and use it in GitHub Desktop.
Save illescasDaniel/b6e07046e0a24bda34b1b98ae2a03823 to your computer and use it in GitHub Desktop.
Bashrc user settings Ubuntu, 2024
# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/home/daniel/anaconda3/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
eval "$__conda_setup"
else
if [ -f "/home/daniel/anaconda3/etc/profile.d/conda.sh" ]; then
. "/home/daniel/anaconda3/etc/profile.d/conda.sh"
else
export PATH="/home/daniel/anaconda3/bin:$PATH"
fi
fi
unset __conda_setup
# <<< conda initialize <<<
# pip _ powerline-shell
_update_ps1() {
PS1=$($HOME/anaconda3/bin/powerline-shell $?)
}
if [[ $TERM != linux && ! $PROMPT_COMMAND =~ _update_ps1 ]]; then
PROMPT_COMMAND="_update_ps1; $PROMPT_COMMAND"
fi
# powerline-shell
## Enable nix
source $HOME/.nix-profile/etc/profile.d/nix.sh
##
## Enable github cli copilot aliases
## ghcs: gh copilot suggest
## ghce: gh copilot explain
eval "$(gh copilot alias -- bash)"
##
#aliases and functions
alias cb="xclip -selection clipboard"
eval "$(zoxide init bash)"
alias l="eza -l --git --git-repos --hyperlink"
alias la="eza -l -a --git --git-repos --hyperlink"
alias lo="eza -l -o --git --git-repos --hyperlink"
alias lao="eza -l -a -o --git --git-repos --hyperlink"
alias lgrid="eza -l --grid --git --git-repos --hyperlink"
alias lagrid="eza -l -a --grid --git --git-repos --hyperlink"
alias ltree="eza -l --tree --git --git-repos --hyperlink"
alias latree="eza -l -a --tree --git --git-repos --hyperlink"
#google drive for vscode
gdrive_mount() {
google-drive-ocamlfuse $HOME/GoogleDrive/
}
gdrive_unmount() {
fusermount -u $HOME/GoogleDrive/
}
# nix
export NIXPKGS_ALLOW_UNFREE=1
nix_search() {
nix --extra-experimental-features "nix-command flakes" search nixpkgs $1
}
nix_install() {
nix-env -iA nixpkgs.$1
}
nix_try() {
nix-shell -p $1
}
nix_uninstall() {
nix-env --uninstall $1
}
nix_list() {
nix-env --query
}
nix_list_installed() {
nix-env --query --compare-versions
}
nix_update_all () {
nix-env --query --compare-versions
nix-channel --update
nix-env -u
}
nix_update_package() {
nix-env --upgrade $1
}
nix_history() {
nix-env --list-generations
}
nix_history_undo() {
nix-env --switch-generation $1
}
nix_clean() {
nix-collect-garbage
nix --extra-experimental-features "nix-command flakes" store optimise
}
nix_deep_clean() {
nix-collect-garbage -d
nix --extra-experimental-features "nix-command flakes" store optimise
}
# apt
apt_refresh() {
sudo nala update
}
apt_update() {
sudo nala update
}
apt_search_fast() {
nala list $1
}
apt_search() {
nala show $1
}
apt_install() {
sudo nala install $1
}
apt_install_simulation() {
apt -s install $1
}
apt_uninstall() {
sudo nala purge $1
}
apt_list() {
nala list --installed
}
apt_update_all() {
sudo nala upgrade
}
apt_update_package() {
sudo apt install --only-upgrade $1
}
apt_history() {
nala history
}
apt_history_undo() {
sudo nala history undo $1
}
apt_clean() {
sudo nala update
sudo nala clean
sudo nala autopurge
}
apt_deep_clean() {
sudo nala update
sudo nala clean
sudo nala history clear --all
sudo nala autoremove
sudo nala autopurge
}
apt_search_file() {
sudo apt-file update
apt-file search $1
}
nvidia_check() {
nvidia-smi
}
# end - aliases
# you can change qt scaling adding: QT_SCALE_FACTOR="1.25" inside /etc/environment
# but it shouldn't be necessary if font scaling is set in gnome tweaks
# Same with this:
# export QT_SCALE_FACTOR=1.25
# initialize brew
eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"
#### fuzzy finder (search files) ####
eval "$(fzf --bash)"
__fzf_display_file_content() {
local FILE="$1"
bat "$FILE" --line-range :500
}
__fzf_display_matches_and_file_content() {
local PATTERN="$1"
local FILE="$2"
rg --pretty "$PATTERN" --context=2 --color=always "$FILE"
echo
__fzf_display_file_content "$FILE"
}
export -f __fzf_display_file_content
export -f __fzf_display_matches_and_file_content
sf() { # search files
# Use awk to add ANSI color codes to file extensions
find . -type f | sed -E $'s|(.*/)([^/]+)(\.[^.]+)$|\\1\e[32m\\2\e[0m\e[34m\\3\e[0m|' | fzf --ansi --multi --preview-window=top,70% --preview '__fzf_display_file_content {}'
}
########
sc() { # search content
if [[ $# -eq 1 ]]; then
local PATTERN="$1"
rg --files-with-matches "$PATTERN" | sed -E $'s|(.*/)([^/]+)(\.[^.]+)$|\\1\e[32m\\2\e[0m\e[36m\\3\e[0m|' | fzf --ansi --multi --preview-window=top,70% --preview "__fzf_display_matches_and_file_content '$PATTERN' {}"
elif [[ $# -eq 2 ]]; then
local PATTERN="$1"
local FILE="$2"
# Replace this with the command you want to run when a file name is provided
rg --files-with-matches "$PATTERN" "$FILE" | fzf --ansi --preview-window=top,70% --preview "__fzf_display_matches_and_file_content '$PATTERN' {}"
else
echo "Error: Incorrect number of arguments provided. Usage: sc <pattern> [file]"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment