From 6127f66f1a3a04a7b8e4e571ebf8b64005557f5c Mon Sep 17 00:00:00 2001 From: coolneng Date: Mon, 2 May 2022 13:17:33 +0200 Subject: [PATCH] Ignore theme specific lines in git using a filter --- git/.config/git/config | 3 + kitty/.config/kitty/kitty.conf | 6 -- neovim/.config/nvim/init.vim | 1 - .../.local/share/scripts/git-ignore-line.sh | 87 +++++++++++++++++++ tmux/.tmux.conf | 2 - 5 files changed, 90 insertions(+), 9 deletions(-) create mode 100755 scripts/.local/share/scripts/git-ignore-line.sh diff --git a/git/.config/git/config b/git/.config/git/config index aa7b043..d2d356c 100644 --- a/git/.config/git/config +++ b/git/.config/git/config @@ -14,3 +14,6 @@ gpgsign = true [gitlab] user = akasroua +[filter "git-ignore-line.sh"] + clean = git-ignore-line.sh + smudge = cat diff --git a/kitty/.config/kitty/kitty.conf b/kitty/.config/kitty/kitty.conf index a023eef..a027c20 100644 --- a/kitty/.config/kitty/kitty.conf +++ b/kitty/.config/kitty/kitty.conf @@ -452,8 +452,6 @@ inactive_tab_font_style normal #: Color scheme {{{ -include iceberg_dark.conf - #: The foreground and background colors background_opacity 1.0 @@ -993,7 +991,3 @@ map kitty_mod+delete clear_terminal reset active # }}} -# BEGIN_KITTY_THEME -# Iceberg Dark -include current-theme.conf -# END_KITTY_THEME \ No newline at end of file diff --git a/neovim/.config/nvim/init.vim b/neovim/.config/nvim/init.vim index 1520405..bad5644 100644 --- a/neovim/.config/nvim/init.vim +++ b/neovim/.config/nvim/init.vim @@ -42,7 +42,6 @@ Plug 'cocopon/iceberg.vim' call plug#end() ""Colors colorscheme iceberg -set bg=dark set termguicolors ""Disabe status line set laststatus=0 diff --git a/scripts/.local/share/scripts/git-ignore-line.sh b/scripts/.local/share/scripts/git-ignore-line.sh new file mode 100755 index 0000000..fe9186c --- /dev/null +++ b/scripts/.local/share/scripts/git-ignore-line.sh @@ -0,0 +1,87 @@ +#!/bin/sh +# Git filter to ignore lines in your files. +# +# Copyright (c) 2017-2019 Aryel Mota Góis +# +# MIT License +# +# +# SETUP: +# +# cp git-ignore-line.sh ~/bin/git-ignore-line +# +# +# USAGE: +# +# Mark single lines you want to ignore with 'GITIGNORE'. It ignores +# the whole line. It is recommended to be inside a comment in your code. +# +# Mark multiple lines surrounding them with 'GITIGNORE START' and +# 'GITIGNORE END'. It can not be nested. +# +# NOTE: Ignored lines might be lost on checkout. +# +# +# Add files to ignore: +# +# git ignore-line +# +# Remove patterns with: +# +# git ignore-line -r +# +# List configured patterns: +# +# git ignore-line -l +# +# PATTERN can be a file or a glob pattern: '*.html'. Remember to +# escape the `*`. +# +# +# TODO: +# +# - Stash the lines ignored by this filter before a git checkout. + + +set -eu + + +# Check if stdin is not tty and remove ignored lines from it. + +[ -t 0 ] || exec sed \ + '/GITIGNORE START/,/GITIGNORE END/d; /GITIGNORE/d' \ + /dev/stdin + + +# Running from tty. + +program=$(basename "$0") + +# Find git repository. +git_dir=$(git rev-parse --git-dir) + +# Path to attributes file. +attr_file=$git_dir/info/attributes + +# Check arguments. +if [ $# -eq 2 ] && [ "$1" = '-r' ]; then + # Remove filter for pattern. + sed "s|^$2 filter=$program||" "$attr_file" > "$attr_file.tmp" + mv -- "$attr_file.tmp" "$attr_file" +elif [ $# -eq 1 ]; then + if [ "$1" = '-l' ]; then + # List patterns. + grep "filter=$program" "$attr_file" || true + else + # Add filter for pattern. + echo "$1 filter=$program" >> "$attr_file" + # Configure filter. + git config --global "filter.$program.clean" "$program" + git config --global "filter.$program.smudge" cat + fi +else + # Show help. + >&2 echo "Usage: $program [-r] " + >&2 echo " or: $program -l" + exit 1 +fi diff --git a/tmux/.tmux.conf b/tmux/.tmux.conf index aab46b1..4720bb1 100644 --- a/tmux/.tmux.conf +++ b/tmux/.tmux.conf @@ -78,5 +78,3 @@ set -g mouse on bind -T root WheelUpPane if-shell -F -t = "#{alternate_on}" "send-keys -M" "select-pane -t =; copy-mode -e; send-keys -M" bind -T root WheelDownPane if-shell -F -t = "#{alternate_on}" "send-keys -M" "select-pane -t =; send-keys -M" -# Colorscheme file -source-file ~/.tmux/iceberg_dark.tmux.conf