refactor(shell): extract aliases into a separate file

This commit is contained in:
spy4x 2024-03-15 17:04:57 +08:00
parent b474666e2a
commit 580478629a
3 changed files with 54 additions and 44 deletions

43
aliases.sh Normal file
View File

@ -0,0 +1,43 @@
# misc START
alias copy="wl-copy <"
alias rs="rsync -avhzru -P"
alias rsh="rsync -avhzru -P -e ssh"
alias ws="webstorm"
alias size="du -hd1 | sort -hr"
alias la='ls -la'
alias list="tree -L 1"
alias tree="tree -L 2"
alias up="pnpm up -i -L"
# misc END
# git START
alias gst="git status"
alias ga="git add"
alias gd="git diff"
alias gb="git branch"
alias gco="git checkout"
alias gc="git commit -m"
alias gp="git push"
alias gl="git pull"
alias glf="git fetch --all && git stash save -m 'Before force pull' && git reset --hard"
alias gr="git restore --staged"
# git END
# docker START
alias dc="docker compose up -d"
alias dd="docker compose down"
alias dclean="docker system prune -af"
# docker END
# webp BEGIN
function to_webp() {
setopt NULL_GLOB
for type in jpg png; do
for F in *.$type; do
cwebp "$F" -o "`basename "$\{F%.$type}"`.webp"
done
done
unsetopt NULL_GLOB
}
alias webp='to_webp'
# webp END

View File

@ -15,6 +15,7 @@ echo "Copying new configuration..."
sudo cp ./configuration.nix "${NIXOS_CONFIG_PATH}" sudo cp ./configuration.nix "${NIXOS_CONFIG_PATH}"
sudo mkdir -p "${NIXOS_CONFIG_PATH}/private" sudo mkdir -p "${NIXOS_CONFIG_PATH}/private"
sudo cp ./private/* "${NIXOS_CONFIG_PATH}/private/" sudo cp ./private/* "${NIXOS_CONFIG_PATH}/private/"
sudo cp ./aliases.sh "${NIXOS_CONFIG_PATH}"
echo "Rebuilding NixOS configuration..." echo "Rebuilding NixOS configuration..."
# Rebuild the NixOS configuration and make the changes effective # Rebuild the NixOS configuration and make the changes effective

View File

@ -5,13 +5,19 @@
{ config, pkgs, lib, ... }: { config, pkgs, lib, ... }:
let let
nixFolder = "/etc/nixos";
username = "spy4x"; username = "spy4x";
userFullName = "Anton Shubin"; userFullName = "Anton Shubin";
sshConfigPath = "${nixFolder}/private/ssh-config";
sshConfig = if builtins.pathExists "${sshConfigPath}" then builtins.readFile "${sshConfigPath}" else "# private ssh config file didn't exist to insert it's content here";
gdrivePath = "/home/${username}/gdrive"; gdrivePath = "/home/${username}/gdrive";
curBin = "/run/current-system/sw/bin"; curBin = "/run/current-system/sw/bin";
nixFolder = "/etc/nixos";
sshConfigPath = "${nixFolder}/private/ssh-config";
sshConfig = if builtins.pathExists "${sshConfigPath}" then builtins.readFile "${sshConfigPath}" else "# private ssh config file didn't exist to insert it's content here";
aliasesPath = "${nixFolder}/aliases.sh";
aliases = if builtins.pathExists "${aliasesPath}" then builtins.readFile "${aliasesPath}" else "# aliases file didn't exist to insert it's content here";
home-manager = builtins.fetchTarball "https://github.com/nix-community/home-manager/archive/release-23.11.tar.gz"; home-manager = builtins.fetchTarball "https://github.com/nix-community/home-manager/archive/release-23.11.tar.gz";
in in
{ {
@ -170,47 +176,7 @@ in
# Shell aliases and other init # Shell aliases and other init
environment.interactiveShellInit = '' environment.interactiveShellInit = ''
alias copy="wl-copy <" ${aliases}
alias rs="rsync -avhzru -P"
alias rsh="rsync -avhzru -P -e ssh"
alias ws="webstorm"
alias size="du -hd1 | sort -hr"
alias la='ls -la'
alias list="tree -L 1"
alias tree="tree -L 2"
alias up="pnpm up -i -L"
# git START
alias gst="git status"
alias ga="git add"
alias gd="git diff"
alias gb="git branch"
alias gco="git checkout"
alias gc="git commit -m"
alias gp="git push"
alias gl="git pull"
alias glf="git fetch --all && git stash save -m 'Before force pull' && git reset --hard"
alias gr="git restore --staged"
# git END
# docker START
alias dc="docker compose up -d"
alias dd="docker compose down"
alias dclean="docker system prune -af"
# docker END
# webp BEGIN
function to_webp() {
setopt NULL_GLOB
for type in jpg png; do
for F in *.$type; do
cwebp "$F" -o "`basename "$\{F%.$type}"`.webp"
done
done
unsetopt NULL_GLOB
}
alias webp='to_webp'
# webp END
''; '';