From 4ed3c348d9bb63b55c9be4f79b29e4f45c7fd97e Mon Sep 17 00:00:00 2001 From: Maximilian Wolf <69987866+MaxWolf-01@users.noreply.github.com> Date: Mon, 20 May 2024 21:49:52 +0200 Subject: [PATCH] add rcat and flatten functions, add check_question_mark_in_filename, comment obsidian vim plugins --- git/hooks/check_question_mark_in_filename | 19 +++++++++++++++++++ setup | 1 + vim/obsidian | 8 +++----- zsh/functions | 21 +++++++++++++++++++-- 4 files changed, 42 insertions(+), 7 deletions(-) create mode 100755 git/hooks/check_question_mark_in_filename diff --git a/git/hooks/check_question_mark_in_filename b/git/hooks/check_question_mark_in_filename new file mode 100755 index 0000000..a697409 --- /dev/null +++ b/git/hooks/check_question_mark_in_filename @@ -0,0 +1,19 @@ +#!/bin/bash + +# pre-commit hook to prevent files with question marks from being committed (Android compatibility) + +files_to_commit=$(git diff --cached --name-only) + +found=false +for file in $files_to_commit; do + if [[ "$file" == *"?"* ]]; then + echo "Error: File '$file' contains a question mark and cannot be committed." + found=true + fi +done + +if [ "$found" = true ]; then + exit 1 +fi + +exit 0 diff --git a/setup b/setup index b247929..e4e5605 100755 --- a/setup +++ b/setup @@ -257,6 +257,7 @@ obsidian_vault() { git clone git@github.com:MaxWolf-01/knowledge-base.git cd knowledge-base && git clone git@github.com:MaxWolf-01/.obsidian-pc.git && mv .obsidian-pc .obsidian || exit ln -sf ~/.dotfiles/vim/obsidian ~/repos/obsidian/knowledge-base/.obsidian.vimrc + ln -sf ~/.dotfiles/git/hooks/check_question_mark_in_filename ~/repos/obsidian/knowledge-base/.git/hooks/pre-commit } obsidian() { diff --git a/vim/obsidian b/vim/obsidian index a88fc4b..3a704a9 100644 --- a/vim/obsidian +++ b/vim/obsidian @@ -8,9 +8,7 @@ noremap L } " Yank to system clipboard set clipboard=unnamed -call plug#begin('~/.vim/plugged') - +"call plug#begin('~/.vim/plugged') " TODO change Ctrl+n to alt+j https://www.reddit.com/r/neovim/comments/17dcy9i/plugin_or_command_for_simultaneous_nonadjacent/ -Plug 'mg979/vim-visual-multi', {'branch': 'master'} - -call plug#end() +"Plug 'mg979/vim-visual-multi', {'branch': 'master'} +"call plug#end() diff --git a/zsh/functions b/zsh/functions index cecbba8..8920208 100644 --- a/zsh/functions +++ b/zsh/functions @@ -192,8 +192,25 @@ function restic_lsfs() { restic ls --json latest | jq -r 'select(.type == "file") | [.path, .size] | @tsv' | sort -k2 -n -r | head -n "$n" | awk -F'\t' '{printf "%s\t%.2f MB\n", $1, $2/1048576}' } -# put the content of a file into the clipboard +# put the content of a file into the clipboard, or read from stdin if no file is provided clip() { - xclip -selection clipboard < "$1" + if [ -z "$1" ]; then + xclip -selection clipboard + else + xclip -selection clipboard < "$1" + fi +} + + +# recursively cat the content of a directory (default current) +function rcat() { + local dir=${1:-.} + find "$dir" -type f -exec cat {} \; +} + +# recursively flatten a directory structure (defalt current dir), skip files with the same name +function flatten() { + local dir=${1:-.} + find "$dir" -mindepth 2 -type f -exec mv -n -t "$dir" {} + }