refactor: move programs into graphical and shell
This commit is contained in:
parent
68047c894e
commit
727d197f41
39 changed files with 68 additions and 62 deletions
11
configs/shell/comma.nix
Normal file
11
configs/shell/comma.nix
Normal file
|
@ -0,0 +1,11 @@
|
|||
{ inputs, ... }:
|
||||
{
|
||||
home-manager.users.rafiq = {
|
||||
imports = [
|
||||
inputs.nix-index-database.hmModules.nix-index
|
||||
];
|
||||
|
||||
programs.nix-index.enable = true;
|
||||
programs.nix-index-database.comma.enable = true;
|
||||
};
|
||||
}
|
39
configs/shell/default.nix
Normal file
39
configs/shell/default.nix
Normal file
|
@ -0,0 +1,39 @@
|
|||
{ pkgs, ... }:
|
||||
{
|
||||
imports = [
|
||||
./scripts
|
||||
./comma.nix
|
||||
./direnv.nix
|
||||
./editorconfig.nix
|
||||
./fzf.nix
|
||||
./git.nix
|
||||
./nh.nix
|
||||
./nvf.nix
|
||||
./starship.nix
|
||||
./tealdeer.nix
|
||||
./yazi.nix
|
||||
./zellij.nix
|
||||
./zoxide.nix
|
||||
./zsh.nix
|
||||
];
|
||||
|
||||
home-manager.users.rafiq.home = {
|
||||
shell.enableShellIntegration = true;
|
||||
shellAliases = {
|
||||
gs = "git status";
|
||||
ai = "aichat -r %shell% -e";
|
||||
cd = "z";
|
||||
list-all-packages = "nix-store --query --requisites /run/current-system | cut -d- -f2- | sort | uniq";
|
||||
};
|
||||
|
||||
packages = with pkgs; [
|
||||
aichat
|
||||
bat
|
||||
btop # add settings as home-manager module
|
||||
devenv
|
||||
fastfetch
|
||||
ripgrep
|
||||
ttyper
|
||||
];
|
||||
};
|
||||
}
|
12
configs/shell/direnv.nix
Normal file
12
configs/shell/direnv.nix
Normal file
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
# direnv lets us declare a .envrc in each project directory
|
||||
# and updates the shell with the packages specified.
|
||||
|
||||
home-manager.users.rafiq = {
|
||||
programs.direnv = {
|
||||
enable = true;
|
||||
enableBashIntegration = true;
|
||||
nix-direnv.enable = true;
|
||||
};
|
||||
};
|
||||
}
|
23
configs/shell/editorconfig.nix
Normal file
23
configs/shell/editorconfig.nix
Normal file
|
@ -0,0 +1,23 @@
|
|||
{
|
||||
home-manager.users.rafiq = {
|
||||
editorconfig = {
|
||||
enable = true;
|
||||
settings = {
|
||||
"*" = {
|
||||
end_of_line = "lf";
|
||||
insert_final_newline = true;
|
||||
trim_trailing_whitespace = true;
|
||||
charset = "utf-8";
|
||||
indent_style = "space";
|
||||
indent_size = 2;
|
||||
};
|
||||
"package.json" = {
|
||||
indent_style = "unset";
|
||||
};
|
||||
"*.lock" = {
|
||||
indent_size = "unset";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
7
configs/shell/fzf.nix
Normal file
7
configs/shell/fzf.nix
Normal file
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
home-manager.users.rafiq = {
|
||||
programs.fzf = {
|
||||
enable = true;
|
||||
};
|
||||
};
|
||||
}
|
21
configs/shell/git.nix
Normal file
21
configs/shell/git.nix
Normal file
|
@ -0,0 +1,21 @@
|
|||
{ config, ... }:
|
||||
{
|
||||
home-manager.users.rafiq = {
|
||||
home.sessionVariables.GIT_CONFIG_GLOBAL = "$HOME/.config/git/config";
|
||||
|
||||
programs.git = {
|
||||
enable = true;
|
||||
userName = "Mohammad Rafiq";
|
||||
userEmail = "mohammadrafiq567@gmail.com";
|
||||
signing.key = "~/.ssh/id_ed25519.pub";
|
||||
signing.signByDefault = true;
|
||||
extraConfig = {
|
||||
init.defaultBranch = "prime";
|
||||
push.autoSetupRemote = true;
|
||||
pull.rebase = false;
|
||||
core.editor = "nvim";
|
||||
gpg.format = "ssh";
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
7
configs/shell/nh.nix
Normal file
7
configs/shell/nh.nix
Normal file
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
home-manager.users.rafiq = {
|
||||
programs.nh = {
|
||||
enable = true;
|
||||
};
|
||||
};
|
||||
}
|
88
configs/shell/nvf.nix
Normal file
88
configs/shell/nvf.nix
Normal file
|
@ -0,0 +1,88 @@
|
|||
{ inputs, pkgs, ... }:
|
||||
{
|
||||
home-manager.users.rafiq = {
|
||||
imports = [
|
||||
inputs.nvf.homeManagerModules.default
|
||||
./nvf/input.nix
|
||||
./nvf/languages.nix
|
||||
./nvf/ui.nix
|
||||
./nvf/utilities.nix
|
||||
];
|
||||
home.sessionVariables.EDITOR = "nvim";
|
||||
programs.nvf = {
|
||||
enable = true;
|
||||
enableManpages = true;
|
||||
settings.vim = {
|
||||
viAlias = true;
|
||||
vimAlias = true;
|
||||
options = {
|
||||
# Indentation
|
||||
autoindent = true;
|
||||
smartindent = true;
|
||||
expandtab = true;
|
||||
smarttab = true;
|
||||
wrap = true;
|
||||
shiftwidth = 2;
|
||||
tabstop = 2;
|
||||
foldlevel = 1000; # Open all folds by default
|
||||
|
||||
# Search
|
||||
hlsearch = true;
|
||||
ignorecase = true;
|
||||
incsearch = true;
|
||||
smartcase = true; # case-sensitive if search contains uppercase
|
||||
|
||||
# Visual
|
||||
number = true;
|
||||
cursorline = true;
|
||||
visualbell = true;
|
||||
termguicolors = true;
|
||||
|
||||
# Input
|
||||
backspace = "indent,eol,start";
|
||||
};
|
||||
keymaps = [
|
||||
{
|
||||
desc = "Open the file path under the cursor, making the file if it doesn't exist.";
|
||||
key = "gf";
|
||||
mode = "n";
|
||||
action = ":cd %:p:h<CR>:e <cfile><CR>";
|
||||
silent = true;
|
||||
}
|
||||
{
|
||||
desc = "Delete the previous word.";
|
||||
key = "<C-BS>";
|
||||
mode = "i";
|
||||
action = "<C-W>";
|
||||
silent = true;
|
||||
}
|
||||
{
|
||||
desc = "Open the filetree.";
|
||||
key = "t";
|
||||
mode = "n";
|
||||
action = ":Yazi<CR>";
|
||||
silent = true;
|
||||
}
|
||||
];
|
||||
luaConfigRC.turn_off_inline_diagnostics =
|
||||
# lua
|
||||
''
|
||||
vim.diagnostic.config({
|
||||
virtual_text = false -- turn off inline diagnostics
|
||||
})
|
||||
'';
|
||||
extraPlugins = with pkgs.vimPlugins; {
|
||||
yuck-vim = {
|
||||
package = yuck-vim;
|
||||
};
|
||||
nvim-treesitter-parsers = {
|
||||
package = nvim-treesitter-parsers.yuck;
|
||||
};
|
||||
nvim-parinfer = {
|
||||
package = nvim-parinfer;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
69
configs/shell/nvf/input.nix
Normal file
69
configs/shell/nvf/input.nix
Normal file
|
@ -0,0 +1,69 @@
|
|||
{ lib, ... }:
|
||||
{
|
||||
programs.nvf.settings.vim = {
|
||||
autopairs.nvim-autopairs.enable = true;
|
||||
snippets.luasnip = {
|
||||
enable = true;
|
||||
setupOpts.enable_autosnippets = true;
|
||||
};
|
||||
autocomplete = {
|
||||
blink-cmp = {
|
||||
enable = true;
|
||||
friendly-snippets.enable = true;
|
||||
setupOpts = {
|
||||
enabled =
|
||||
lib.generators.mkLuaInline
|
||||
# lua
|
||||
''
|
||||
--- Disable completion for markdown
|
||||
function()
|
||||
return not vim.tbl_contains({"markdown"}, vim.bo.filetype)
|
||||
and vim.bo.buftype ~= "prompt"
|
||||
and vim.b.completion ~= false
|
||||
end
|
||||
'';
|
||||
cmdline = {
|
||||
enabled = true;
|
||||
sources = null;
|
||||
completion.menu.auto_show = false;
|
||||
};
|
||||
#completion.menu.auto_show =
|
||||
# lib.generators.mkLuaInline
|
||||
# # lua
|
||||
# ''
|
||||
# function(ctx)
|
||||
# --- Get the cursor position from the current window
|
||||
# local row, column = unpack(vim.api.nvim_win_get_cursor(0))
|
||||
# --- Get the current row (1 is Neovim API giving us 1-based indexing)
|
||||
# --- Get the current column but don't return negative numbers
|
||||
# --- ignore_injections are to ignore embedded code
|
||||
# --- success is the result, node is the syntax node object
|
||||
# local success, node = pcall(vim.treesitter.get_node, {
|
||||
# pos = {row - 1, math.max(0, column - 1)},
|
||||
# ignore_injections = false
|
||||
# })
|
||||
# --- Types of nodes to ignore
|
||||
# local reject = {"comment", "line_comment", "block_comment", "string_start", "string_content", "string_end" }
|
||||
# --- If the node type is in the reject table, don't show the completion
|
||||
# if success and node and vim.tbl_contains(reject, node:type()) then
|
||||
# return false;
|
||||
# end
|
||||
# -- whatever other logic you want beyond this
|
||||
# return true
|
||||
# end
|
||||
# '';
|
||||
# menu.auto_show = false;
|
||||
completion.documentation.auto_show_delay_ms = 0;
|
||||
signature.enabled = true;
|
||||
};
|
||||
};
|
||||
};
|
||||
utility = {
|
||||
motion = {
|
||||
hop.enable = true; # <leader>h
|
||||
precognition.enable = false;
|
||||
};
|
||||
yanky-nvim.enable = true;
|
||||
};
|
||||
};
|
||||
}
|
19
configs/shell/nvf/languages.nix
Normal file
19
configs/shell/nvf/languages.nix
Normal file
|
@ -0,0 +1,19 @@
|
|||
{
|
||||
programs.nvf.settings.vim.languages = {
|
||||
# The below settings enable defaults for all languages
|
||||
enableDAP = true;
|
||||
enableExtraDiagnostics = true;
|
||||
enableFormat = true;
|
||||
enableLSP = true;
|
||||
enableTreesitter = true;
|
||||
|
||||
# Enable specific languages
|
||||
nix.enable = true;
|
||||
nix.format.type = "nixfmt";
|
||||
rust.enable = true;
|
||||
clang.enable = true;
|
||||
lua.enable = true;
|
||||
python.enable = true;
|
||||
css.enable = true;
|
||||
};
|
||||
}
|
52
configs/shell/nvf/ui.nix
Normal file
52
configs/shell/nvf/ui.nix
Normal file
|
@ -0,0 +1,52 @@
|
|||
{
|
||||
programs.nvf.settings.vim = {
|
||||
lsp = {
|
||||
formatOnSave = true;
|
||||
lightbulb.enable = true;
|
||||
lspkind.enable = true;
|
||||
otter-nvim.enable = true;
|
||||
trouble.enable = true;
|
||||
};
|
||||
binds = {
|
||||
cheatsheet.enable = true;
|
||||
whichKey.enable = true;
|
||||
};
|
||||
debugger.nvim-dap = {
|
||||
enable = true;
|
||||
ui.enable = true;
|
||||
};
|
||||
notes.todo-comments.enable = true;
|
||||
telescope.enable = true;
|
||||
statusline.lualine.enable = true;
|
||||
treesitter = {
|
||||
enable = true;
|
||||
autotagHtml = true;
|
||||
fold = true;
|
||||
};
|
||||
notify.nvim-notify.enable = true;
|
||||
visuals = {
|
||||
fidget-nvim.enable = true;
|
||||
indent-blankline.enable = true;
|
||||
rainbow-delimiters.enable = true;
|
||||
nvim-web-devicons.enable = true;
|
||||
tiny-devicons-auto-colors.enable = true;
|
||||
};
|
||||
ui = {
|
||||
borders.enable = true;
|
||||
breadcrumbs.enable = true;
|
||||
breadcrumbs.navbuddy.enable = true;
|
||||
colorizer.enable = true;
|
||||
noice.enable = true;
|
||||
nvim-ufo.enable = true;
|
||||
};
|
||||
utility = {
|
||||
ccc.enable = true;
|
||||
images.image-nvim = {
|
||||
enable = true;
|
||||
setupOpts.backend = "kitty";
|
||||
};
|
||||
yazi-nvim.enable = true;
|
||||
yazi-nvim.setupOpts.open_for_directories = true; # FIXME: does this work with neotree?
|
||||
};
|
||||
};
|
||||
}
|
22
configs/shell/nvf/utilities.nix
Normal file
22
configs/shell/nvf/utilities.nix
Normal file
|
@ -0,0 +1,22 @@
|
|||
{
|
||||
programs.nvf.settings.vim = {
|
||||
utility = {
|
||||
direnv.enable = true;
|
||||
nix-develop.enable = true;
|
||||
leetcode-nvim = {
|
||||
enable = true;
|
||||
setupOpts = {
|
||||
image_support = true; # requires image.nvim
|
||||
lang = "rust";
|
||||
};
|
||||
};
|
||||
mkdir.enable = true;
|
||||
new-file-template = {
|
||||
enable = true;
|
||||
# add a directory containing lua/tempaltes/*.lua to vim.additionalRuntimePaths
|
||||
# TODO: add for nix
|
||||
};
|
||||
};
|
||||
session.nvim-session-manager.enable = true;
|
||||
};
|
||||
}
|
40
configs/shell/scripts/byebye.sh
Normal file
40
configs/shell/scripts/byebye.sh
Normal file
|
@ -0,0 +1,40 @@
|
|||
# Set up the terminal to read input immediately, without waiting for Enter.
|
||||
# This is done using the `stty` command.
|
||||
# `stty` controls terminal settings.
|
||||
# `-icanon` disables canonical mode. In canonical mode, the terminal buffers input until a newline is received. Disabling it makes input available immediately.
|
||||
# `min 1` specifies that at least 1 character should be read.
|
||||
# `time 0` specifies that the read should return immediately if a character is available.
|
||||
stty -icanon min 1 time 0
|
||||
|
||||
# Prompt the user to enter 'y' or 'n' to confirm or cancel the poweroff.
|
||||
# `echo -n` prints the prompt without a trailing newline, so the input will appear on the same line.
|
||||
echo -n "Poweroff system? (y/n) [n]: "
|
||||
|
||||
# Read a single character from the input and store it in the 'answer' variable.
|
||||
# `read -n 1 answer` reads only 1 character.
|
||||
read -n 1 answer
|
||||
|
||||
# Print a newline character after the input has been read.
|
||||
# This makes the output more readable, as the subsequent messages will appear on a new line.
|
||||
echo
|
||||
|
||||
# Restore the terminal settings to their default values.
|
||||
# This is important, as leaving the terminal in non-canonical mode can cause unexpected behavior.
|
||||
# `stty icanon` re-enables canonical mode.
|
||||
stty icanon
|
||||
|
||||
# Check the value of the 'answer' variable.
|
||||
# `[[ ... ]]` is a more robust and feature-rich way to perform conditional tests than `[ ... ]`.
|
||||
# `"y"` matches only the lowercase "y". If you want case-insensitive matching, consider using `[[ ${answer,,} == "y" ]]` (converts answer to lowercase).
|
||||
if [[ "$answer" == "y" ]]; then
|
||||
# If the user entered 'y', proceed with the poweroff.
|
||||
echo "Powering off..."
|
||||
|
||||
# Execute the systemctl poweroff command with root privileges using sudo.
|
||||
# `sudo` allows you to run commands as the superuser (root).
|
||||
# `systemctl poweroff` sends the command to the systemd init system to shut down the machine.
|
||||
sudo systemctl poweroff
|
||||
else
|
||||
# If the user entered anything other than 'y', cancel the poweroff.
|
||||
echo "Poweroff cancelled."
|
||||
fi
|
16
configs/shell/scripts/default.nix
Normal file
16
configs/shell/scripts/default.nix
Normal file
|
@ -0,0 +1,16 @@
|
|||
{ pkgs, ... }:
|
||||
{
|
||||
home-manager.users.rafiq = {
|
||||
home.packages = [
|
||||
(pkgs.writers.writePython3Bin "git-extract" {
|
||||
libraries = with pkgs.python3Packages; [
|
||||
magic
|
||||
chardet
|
||||
];
|
||||
} (builtins.readFile ./git-extract.py))
|
||||
|
||||
(pkgs.writeShellScriptBin "rebuild" (builtins.readFile ./rebuild.sh))
|
||||
(pkgs.writeShellScriptBin "byebye" (builtins.readFile ./byebye.sh))
|
||||
];
|
||||
};
|
||||
}
|
317
configs/shell/scripts/git-extract.py
Normal file
317
configs/shell/scripts/git-extract.py
Normal file
|
@ -0,0 +1,317 @@
|
|||
# flake8: noqa: E501
|
||||
import subprocess
|
||||
import os
|
||||
import tempfile
|
||||
import shutil
|
||||
import argparse
|
||||
import magic
|
||||
import chardet
|
||||
import math
|
||||
|
||||
|
||||
def is_ascii(file_path):
|
||||
"""
|
||||
Checks if a file contains only ASCII characters.
|
||||
|
||||
Args:
|
||||
file_path (str): The path to the file.
|
||||
|
||||
Returns:
|
||||
bool: True if the file contains only ASCII characters, False otherwise.
|
||||
None: If the file does not exist.
|
||||
"""
|
||||
if not os.path.exists(file_path):
|
||||
return None # Indicate file not found.
|
||||
|
||||
try:
|
||||
with open(file_path, "r", encoding="ascii") as f:
|
||||
f.read() # Attempt to read the entire file as ASCII
|
||||
return True
|
||||
except UnicodeDecodeError:
|
||||
return False
|
||||
|
||||
|
||||
def has_high_entropy(file_path, threshold=0.7):
|
||||
"""
|
||||
Checks if a file has high entropy, which might indicate it's not text.
|
||||
|
||||
Args:
|
||||
file_path (str): The path to the file.
|
||||
threshold (float): Entropy threshold above which it's considered high entropy.
|
||||
|
||||
Returns:
|
||||
bool: True if entropy is above the threshold, False otherwise.
|
||||
None: If the file does not exist.
|
||||
"""
|
||||
if not os.path.exists(file_path):
|
||||
return None
|
||||
|
||||
try:
|
||||
with open(file_path, "rb") as f: # Important: Read as binary
|
||||
data = f.read()
|
||||
except IOError:
|
||||
return True # Treat as non-text if there is an I/O error
|
||||
|
||||
if not data:
|
||||
return False # empty files considered text
|
||||
|
||||
entropy = calculate_entropy(data)
|
||||
return entropy > threshold
|
||||
|
||||
|
||||
def calculate_entropy(data):
|
||||
"""
|
||||
Calculates the entropy of a byte string.
|
||||
|
||||
Args:
|
||||
data (bytes): The byte string.
|
||||
|
||||
Returns:
|
||||
float: The entropy.
|
||||
"""
|
||||
if not data:
|
||||
return 0.0 # Avoid log(0)
|
||||
|
||||
entropy = 0
|
||||
data_length = len(data)
|
||||
seen_bytes = bytearray(range(256)) # All possible byte values
|
||||
counts = [0] * 256
|
||||
|
||||
for byte in data:
|
||||
counts[byte] += 1
|
||||
|
||||
for byte in seen_bytes:
|
||||
probability = float(counts[byte]) / data_length
|
||||
if probability > 0:
|
||||
entropy -= probability * math.log(probability, 2)
|
||||
|
||||
return entropy
|
||||
|
||||
|
||||
def check_chardet_encoding(file_path, confidence_threshold=0.8):
|
||||
"""
|
||||
Checks the file encoding using chardet library.
|
||||
|
||||
Args:
|
||||
file_path (str): The path to the file.
|
||||
confidence_threshold (float): The minimum confidence level for encoding detection.
|
||||
|
||||
Returns:
|
||||
bool: True if the encoding is detected with high confidence and is a text encoding, False otherwise.
|
||||
None: If the file does not exist.
|
||||
"""
|
||||
if not os.path.exists(file_path):
|
||||
return None
|
||||
|
||||
try:
|
||||
with open(file_path, "rb") as f: # Important: Read as binary
|
||||
data = f.read()
|
||||
except IOError:
|
||||
return False # If file can't be opened, assume it's not a simple text file.
|
||||
|
||||
if not data:
|
||||
return True # Empty files are usually considered text
|
||||
|
||||
result = chardet.detect(data)
|
||||
encoding = result["encoding"]
|
||||
confidence = result["confidence"]
|
||||
|
||||
if encoding and confidence > confidence_threshold:
|
||||
# Check if it's a recognized text encoding (not binary or None)
|
||||
if encoding != "binary" and encoding is not None:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def is_text_file(file_path, aggressive=False):
|
||||
"""
|
||||
Wrapper function to check if a file is a text file using multiple methods.
|
||||
|
||||
Args:
|
||||
file_path (str): The path to the file.
|
||||
aggressive (bool, optional): If True, combines all checks for stricter verification.
|
||||
If False, returns True if any check passes. Defaults to False.
|
||||
|
||||
Returns:
|
||||
bool: True if the file is a text file, False otherwise.
|
||||
None: If the file does not exist.
|
||||
"""
|
||||
|
||||
if not os.path.exists(file_path):
|
||||
return None
|
||||
|
||||
# Basic checks
|
||||
ascii_check = is_ascii(file_path)
|
||||
if ascii_check is None:
|
||||
return None # File not found
|
||||
|
||||
if aggressive:
|
||||
# Run all checks and require them all to pass
|
||||
high_entropy_check = not has_high_entropy(
|
||||
file_path
|
||||
) # Invert because we want to know if it DOESN'T have high entropy
|
||||
chardet_check = check_chardet_encoding(file_path)
|
||||
|
||||
return ascii_check and high_entropy_check and chardet_check
|
||||
else:
|
||||
# Run checks and return True if any of them pass
|
||||
high_entropy_check = not has_high_entropy(file_path)
|
||||
chardet_check = check_chardet_encoding(file_path)
|
||||
return ascii_check or high_entropy_check or chardet_check
|
||||
|
||||
|
||||
def get_latest_text_files_to_stdout(remote_repo_url=None, ignored_files=None):
|
||||
"""
|
||||
Checks out the latest commit from a remote Git repository or the current
|
||||
working directory (if no URL is provided) to a temporary folder,
|
||||
and then prints the contents of all files identified as text files to stdout,
|
||||
prepended by their relative paths from the repository root, excluding specified
|
||||
ignored files. Supports "!" to specify includes only.
|
||||
|
||||
Args:
|
||||
remote_repo_url: The URL of the remote Git repository (optional). If None,
|
||||
the current working directory is assumed to be a Git repo.
|
||||
ignored_files: A list of files or directories to ignore (relative to the repo root).
|
||||
If a list contains a value starting with "!", it means "include only".
|
||||
"""
|
||||
|
||||
temp_dir = None
|
||||
if ignored_files is None:
|
||||
ignored_files = []
|
||||
|
||||
# Ensure .git and .gitignore are always ignored (unless include only is specified)
|
||||
include_only = any(item.startswith("!") for item in ignored_files)
|
||||
if not include_only:
|
||||
ignored_files.extend([".git", ".gitignore"])
|
||||
ignored_files = list(set(ignored_files)) # remove duplicates
|
||||
|
||||
# Determine if "include only" is active and extract the include paths
|
||||
include_only = any(item.startswith("!") for item in ignored_files)
|
||||
include_paths = [item[1:] for item in ignored_files if item.startswith("!")]
|
||||
ignore_paths = [item for item in ignored_files if not item.startswith("!")]
|
||||
|
||||
|
||||
try:
|
||||
# Create a temporary directory
|
||||
temp_dir = tempfile.mkdtemp()
|
||||
|
||||
# Clone the repository, but only the latest commit (shallow clone)
|
||||
clone_command = ["git", "clone", "--depth", "1"]
|
||||
if remote_repo_url:
|
||||
clone_command.extend([remote_repo_url, temp_dir])
|
||||
else:
|
||||
# Check if the current directory is a Git repository.
|
||||
try:
|
||||
subprocess.run(
|
||||
["git", "rev-parse", "--is-inside-work-tree"],
|
||||
check=True,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
cwd=os.getcwd(),
|
||||
) # run in current directory
|
||||
except subprocess.CalledProcessError:
|
||||
raise ValueError(
|
||||
"No Git repository URL provided and current directory is not a Git repository."
|
||||
)
|
||||
clone_command.extend([os.getcwd(), temp_dir]) # clone current dir to temp
|
||||
|
||||
subprocess.run(clone_command, check=True, capture_output=True, text=True)
|
||||
|
||||
# Find all files and filter for text files
|
||||
text_files = []
|
||||
for root, _, files in os.walk(temp_dir):
|
||||
for file in files:
|
||||
file_path = os.path.join(root, file)
|
||||
relative_path = os.path.relpath(file_path, temp_dir)
|
||||
|
||||
if include_only:
|
||||
# Include only logic
|
||||
include = False
|
||||
for include_path in include_paths:
|
||||
if relative_path.startswith(include_path):
|
||||
include = True
|
||||
break
|
||||
if not include:
|
||||
continue # Skip if not in include paths
|
||||
else:
|
||||
# Ignore logic (standard ignore)
|
||||
ignore = False
|
||||
path_components = relative_path.split(
|
||||
os.sep
|
||||
) # split based on OS-specific path separator
|
||||
current_path = ""
|
||||
for component in path_components:
|
||||
current_path = (
|
||||
os.path.join(current_path, component)
|
||||
if current_path
|
||||
else component
|
||||
) # prevent empty first join
|
||||
if current_path in ignore_paths:
|
||||
ignore = True
|
||||
break
|
||||
if ignore:
|
||||
continue
|
||||
|
||||
if is_text_file(file_path): # Use the is_text_file function
|
||||
text_files.append(file_path)
|
||||
|
||||
# Print the contents of each text file, prepended by its relative path
|
||||
for file_path in text_files:
|
||||
relative_path = os.path.relpath(file_path, temp_dir)
|
||||
print(f"--- {relative_path} ---")
|
||||
try:
|
||||
with open(file_path, "r", encoding="utf-8") as f: # Use UTF-8 encoding
|
||||
print(f.read())
|
||||
except UnicodeDecodeError:
|
||||
print(
|
||||
f"Error: Could not decode file {relative_path} using UTF-8. Skipping file contents."
|
||||
) # handle binary or other non-UTF-8 encodings
|
||||
print() # Add a blank line between files
|
||||
|
||||
except subprocess.CalledProcessError as e:
|
||||
print(f"Error executing Git command: {e.stderr}")
|
||||
except ValueError as e:
|
||||
print(e)
|
||||
except Exception as e:
|
||||
print(f"An error occurred: {e}")
|
||||
finally:
|
||||
# Clean up the temporary directory
|
||||
if temp_dir:
|
||||
shutil.rmtree(temp_dir)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser(
|
||||
description="Checkout and print text files from a remote Git repository."
|
||||
)
|
||||
parser.add_argument(
|
||||
"-r",
|
||||
"--repo",
|
||||
required=False,
|
||||
help="The URL of the remote Git repository. If not provided, the current directory is used if it's a Git repository.",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-i",
|
||||
"--ignored-files",
|
||||
nargs="+",
|
||||
default=[],
|
||||
help="Files or directories to ignore (space-separated). Use !<path> to specify include only.",
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
remote_repository_url = args.repo
|
||||
ignored_files = args.ignored_files
|
||||
|
||||
# Verify the URL only if it's provided
|
||||
if remote_repository_url:
|
||||
if (
|
||||
"github.com" not in remote_repository_url
|
||||
and "gitlab.com" not in remote_repository_url
|
||||
and "bitbucket.org" not in remote_repository_url
|
||||
):
|
||||
print(
|
||||
"Warning: This script is designed for common public repository hosting providers. Ensure the Git URL is correct."
|
||||
)
|
||||
|
||||
get_latest_text_files_to_stdout(remote_repository_url, ignored_files)
|
3
configs/shell/scripts/rebuild.sh
Executable file
3
configs/shell/scripts/rebuild.sh
Executable file
|
@ -0,0 +1,3 @@
|
|||
git add .
|
||||
# nh clean all
|
||||
nh os switch .
|
16
configs/shell/starship.nix
Normal file
16
configs/shell/starship.nix
Normal file
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
home-manager.users.rafiq = {
|
||||
programs.starship = {
|
||||
enable = true;
|
||||
settings = {
|
||||
add_newline = false;
|
||||
format = "$character";
|
||||
right_format = "$all";
|
||||
character = {
|
||||
success_symbol = "[\\$](bold green)";
|
||||
error_symbol = "[\\$](bold red)";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
8
configs/shell/tealdeer.nix
Normal file
8
configs/shell/tealdeer.nix
Normal file
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
home-manager.users.rafiq = {
|
||||
programs.tealdeer = {
|
||||
enable = true;
|
||||
enableAutoUpdates = true;
|
||||
};
|
||||
};
|
||||
}
|
129
configs/shell/yazi.nix
Normal file
129
configs/shell/yazi.nix
Normal file
|
@ -0,0 +1,129 @@
|
|||
{
|
||||
inputs,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
let
|
||||
yazi-plugins = pkgs.fetchFromGitHub {
|
||||
owner = "yazi-rs";
|
||||
repo = "plugins";
|
||||
rev = "273019910c1111a388dd20e057606016f4bd0d17";
|
||||
hash = "sha256-80mR86UWgD11XuzpVNn56fmGRkvj0af2cFaZkU8M31I=";
|
||||
};
|
||||
in
|
||||
{
|
||||
home-manager.users.rafiq = {
|
||||
programs.yazi = {
|
||||
enable = true;
|
||||
package = inputs.yazi.packages.${pkgs.system}.default;
|
||||
shellWrapperName = "y";
|
||||
# yazi.toml
|
||||
settings = {
|
||||
manager = {
|
||||
sort_by = "natural"; # Sort naturally, e.g. 1.md < 2.md < 10.md
|
||||
sort_translit = true; # Transliterate filenames for sorting
|
||||
show_hidden = true;
|
||||
};
|
||||
plugin = {
|
||||
prepend_preloaders = [
|
||||
{
|
||||
mime = "{audio,video,image}/*";
|
||||
run = "mediainfo";
|
||||
}
|
||||
{
|
||||
mime = "application/subrip";
|
||||
run = "mediainfo";
|
||||
}
|
||||
];
|
||||
prepend_previewers = [
|
||||
{
|
||||
name = "*.md";
|
||||
run = "glow";
|
||||
}
|
||||
{
|
||||
mime = "{audio,video,image}/*";
|
||||
run = "mediainfo";
|
||||
}
|
||||
{
|
||||
mime = "application/subrip";
|
||||
run = "mediainfo";
|
||||
}
|
||||
];
|
||||
prepend_fetchers = [
|
||||
{
|
||||
id = "git";
|
||||
name = "*";
|
||||
run = "git";
|
||||
}
|
||||
{
|
||||
id = "git";
|
||||
name = "*/";
|
||||
run = "git";
|
||||
}
|
||||
];
|
||||
};
|
||||
};
|
||||
# ~/.config/yazi/keymap.toml
|
||||
keymap = {
|
||||
manager.prepend_keymap = [
|
||||
{
|
||||
on = "l";
|
||||
run = "plugin smart-enter";
|
||||
desc = "Enter the child directory or open the file.";
|
||||
}
|
||||
{
|
||||
on = "M";
|
||||
run = "plugin mount";
|
||||
desc = "Open the mount.yazi menu.";
|
||||
}
|
||||
];
|
||||
};
|
||||
plugins = {
|
||||
full-border = "${yazi-plugins}/full-border.yazi";
|
||||
smart-enter = "${yazi-plugins}/smart-enter.yazi";
|
||||
git = "${yazi-plugins}/git.yazi";
|
||||
mount = "${yazi-plugins}/mount.yazi";
|
||||
glow = pkgs.fetchFromGitHub {
|
||||
owner = "Reledia";
|
||||
repo = "glow.yazi";
|
||||
rev = "c76bf4fb612079480d305fe6fe570bddfe4f99d3";
|
||||
sha256 = "sha256-DPud1Mfagl2z490f5L69ZPnZmVCa0ROXtFeDbEegBBU=";
|
||||
};
|
||||
mediainfo = pkgs.fetchFromGitHub {
|
||||
owner = "boydaihungst";
|
||||
repo = "mediainfo.yazi";
|
||||
rev = "447fe95239a488459cfdbd12f3293d91ac6ae0d7";
|
||||
sha256 = "sha256-U6rr3TrFTtnibrwJdJ4rN2Xco4Bt4QbwEVUTNXlWRps=";
|
||||
};
|
||||
starship = pkgs.fetchFromGitHub {
|
||||
owner = "Rolv-Apneseth";
|
||||
repo = "starship.yazi";
|
||||
rev = "6c639b474aabb17f5fecce18a4c97bf90b016512";
|
||||
sha256 = "sha256-bhLUziCDnF4QDCyysRn7Az35RAy8ibZIVUzoPgyEO1A=";
|
||||
};
|
||||
};
|
||||
initLua = ''
|
||||
require("full-border"):setup()
|
||||
require("git"):setup()
|
||||
require("starship"):setup({
|
||||
config_file = "${./yazi/starship.toml}",
|
||||
})
|
||||
'';
|
||||
};
|
||||
home.packages = with pkgs; [
|
||||
jq # JSON preview
|
||||
poppler_utils # PDF preview
|
||||
_7zz # archive extraction and preview
|
||||
ffmpeg
|
||||
ffmpegthumbnailer # video thumbnails
|
||||
fd # file searching
|
||||
ripgrep # file content searching
|
||||
fzf # quick file subtree navigation
|
||||
zoxide # historical directories navigation
|
||||
imagemagick # SVG, font, HEIC, JPEG preview
|
||||
chafa # image/gif preview
|
||||
glow # markdown preview
|
||||
mediainfo # media metadata
|
||||
];
|
||||
};
|
||||
}
|
1
configs/shell/yazi/starship.toml
Normal file
1
configs/shell/yazi/starship.toml
Normal file
|
@ -0,0 +1 @@
|
|||
format = "$all"
|
14
configs/shell/zellij.nix
Normal file
14
configs/shell/zellij.nix
Normal file
|
@ -0,0 +1,14 @@
|
|||
{
|
||||
home-manager.users.rafiq = {
|
||||
programs.zellij = {
|
||||
enable = true;
|
||||
settings = {
|
||||
mouse_mode = false;
|
||||
keybinds.unbind = [
|
||||
"Ctrl h"
|
||||
];
|
||||
};
|
||||
};
|
||||
home.sessionVariables.ZELLIJ_AUTO_ATTACH = "true";
|
||||
};
|
||||
}
|
7
configs/shell/zoxide.nix
Normal file
7
configs/shell/zoxide.nix
Normal file
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
home-manager.users.rafiq = {
|
||||
programs.zoxide = {
|
||||
enable = true;
|
||||
};
|
||||
};
|
||||
}
|
41
configs/shell/zsh.nix
Normal file
41
configs/shell/zsh.nix
Normal file
|
@ -0,0 +1,41 @@
|
|||
{
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
{
|
||||
programs.zsh = {
|
||||
enable = true;
|
||||
};
|
||||
users.defaultUserShell = pkgs.zsh;
|
||||
environment.pathsToLink = [ "/share/zsh" ]; # enables completion
|
||||
home-manager.users.rafiq = {
|
||||
programs.zsh = {
|
||||
enable = true;
|
||||
enableCompletion = true;
|
||||
enableVteIntegration = true;
|
||||
dirHashes = {
|
||||
repos = "$HOME/GitRepos";
|
||||
dl = "$HOME/Downloads";
|
||||
};
|
||||
initContent = # zsh
|
||||
''
|
||||
# Bind CTRL+Backspace to delete whole word
|
||||
bindkey '^H' backward-kill-word
|
||||
'';
|
||||
# TODO: Look into whether we need to add the history attribute
|
||||
profileExtra = # bash
|
||||
''
|
||||
if [ -z "$WAYLAND_DISPLAY" ] && [ "$XDG_VTNR" -eq 1 ]; then
|
||||
dbus-run-session Hyprland
|
||||
fi
|
||||
'';
|
||||
plugins = [
|
||||
{
|
||||
name = "vi-mode";
|
||||
src = pkgs.zsh-vi-mode;
|
||||
file = "share/zsh-vi-mode/zsh-vi-mode.plugin.zsh";
|
||||
}
|
||||
];
|
||||
};
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue