From 1be76e6c709f95a1a8a631abbddee9d8f89ea7cc Mon Sep 17 00:00:00 2001 From: davidovski Date: Sat, 1 Nov 2025 13:34:24 +0000 Subject: add xrandr script --- .local/share/kaomoji | 6 +- Xdefaults | 2 +- config/bspwm/bspwmrc | 1 + config/polybar/launch.sh | 21 ++++- config/sxhkd/sxhkdrc | 4 + config/vim/vimrc | 225 ++++++++++++++++++++++++++++++++++------------- mkshrc | 2 +- scripts/toggle-mic.sh | 4 + scripts/xrandr.sh | 35 ++++++++ 9 files changed, 233 insertions(+), 67 deletions(-) create mode 100755 scripts/toggle-mic.sh create mode 100755 scripts/xrandr.sh diff --git a/.local/share/kaomoji b/.local/share/kaomoji index b03258a..8e98b20 100644 --- a/.local/share/kaomoji +++ b/.local/share/kaomoji @@ -1,3 +1,7 @@ +ᵔᴗᵔ smile +ᐢᗜᐢ :D +˘ᗜ˘ :D +˃ᗜ˂ smile ʕ•ₒ•ʔ Bear Shocked ʕ•ᴥ•ʔ Bear ʕ ·ᴥ·ʔ RBear @@ -451,4 +455,4 @@ o(>< )o⌒* Mad (3) (;^_^)ッ☆( ゜o゜) Slapping \(~O~)/ Good Morning \_(´▽`)♪_/ Bathtub -( • )( • )ԅ(≖‿≖ԅ) BOOB +( • )( • )ԅ(≖‿≖ԅ) BOOB diff --git a/Xdefaults b/Xdefaults index 8364b21..43aae41 100644 --- a/Xdefaults +++ b/Xdefaults @@ -57,7 +57,7 @@ dzen2.font: mononoki URxvt*depth: 32 ! *.font: mononoki:minispace=False:size=10:antialias=true -*.font: FiraMono Nerd Font:minispace=False:size=10:antialias=true +*.font: FiraMono Nerd Font:size=10:antialias=true URxvt.font: font1,font2,font3,font4 URxvt.boldFont: font1:style=bold,font2:style=bold,font3:style=bold,font4 diff --git a/config/bspwm/bspwmrc b/config/bspwm/bspwmrc index c138806..640d404 100755 --- a/config/bspwm/bspwmrc +++ b/config/bspwm/bspwmrc @@ -15,6 +15,7 @@ pgrep -x picom > /dev/null || picom & pgrep -x xss-lock > /dev/null || xss-lock slock & pgrep -x bg.sh > /dev/null || $HOME/.scripts/bg.sh > /dev/null & +[ -f "$HOME/.scripts/xrandr.sh" ] && . $HOME/.scripts/xrandr.sh [ -f "$HOME/.config/xrandr.sh" ] && . $HOME/.config/xrandr.sh primary=$(bspc query --monitors -m primary) diff --git a/config/polybar/launch.sh b/config/polybar/launch.sh index f9ece03..71d5923 100755 --- a/config/polybar/launch.sh +++ b/config/polybar/launch.sh @@ -13,13 +13,26 @@ while pgrep -u $UID -x polybar >/dev/null; do sleep 0.1; done polybar -m | while read -r mon; do export MONITOR=$(echo $mon | cut -d: -f1) + width="$(echo $mon | cut -d' ' -f2 | cut -dx -f1)" + w=1920 + case "$width" in + 1920) w=1920 + ;; + 1080) w=1080 + ;; + 2560) w=2560 + ;; + *) w=1920 + esac + echo $mon | grep -q "(primary)" && { polybar ws & - polybar time2560 & - polybar right2560 & - polybar mpd2560 & + + polybar time$w & + polybar right$w & + polybar mpd$w & } || { polybar ws & - polybar time1080 & + polybar time$w & } done diff --git a/config/sxhkd/sxhkdrc b/config/sxhkd/sxhkdrc index dbc0512..3853a32 100644 --- a/config/sxhkd/sxhkdrc +++ b/config/sxhkd/sxhkdrc @@ -75,6 +75,10 @@ super + i super + semicolon bspc rule -a \* -o state=floating && $TERMINAL -e pulsemixer +# xrandr switcher +super + apostrophe + $HOME/.scripts/xrandr.sh + # xkill ctrl + alt + Escape xkill diff --git a/config/vim/vimrc b/config/vim/vimrc index b348907..74515ba 100644 --- a/config/vim/vimrc +++ b/config/vim/vimrc @@ -1,4 +1,4 @@ -set viminfo+=n~/.config/vim/viminfo +"set viminfo+=~/.config/vim/viminfo set runtimepath+=~/.config/vim,~/.config/vim/after set autoindent set wrap @@ -53,69 +53,80 @@ Plug 'preservim/vim-markdown' "let g:vim_markdown_json_frontmatter = 1 -Plug 'neoclide/coc.nvim' -hi CocInlayHint ctermbg=Black ctermfg=Gray - -set updatetime=300 -set signcolumn=yes - -nmap [g (coc-diagnostic-prev) -nmap ]g (coc-diagnostic-next) - -nmap gd (coc-definition) -nmap gy (coc-type-definition) -nmap gi (coc-implementation) -nmap gr (coc-references) - -xmap f (coc-format-selected) -nmap f (coc-format-selected) - -nmap rn (coc-rename) -nmap re (coc-codeaction-refactor) -xmap r (coc-codeaction-refactor-selected) -" nmap r (coc-codeaction-refactor-selected) - -inoremap - \ coc#pum#visible() ? coc#pum#next(1) : - \ CheckBackspace() ? "\" : - \ coc#refresh() -inoremap coc#pum#visible() ? coc#pum#prev(1) : "\" - -inoremap coc#pum#visible() ? coc#pum#confirm() - \: "\u\\=coc#on_enter()\" - -function! CheckBackspace() abort - let col = col('.') - 1 - return !col || getline('.')[col - 1] =~# '\s' -endfunction - - -if has('nvim') - inoremap coc#refresh() -else - inoremap coc#refresh() -endif - -xmap a (coc-codeaction-selected) -nmap a (coc-codeaction-selected) - -" autocmd CursorHold * silent call CocActionAsync('highlight') +"Plug 'neoclide/coc.nvim' +"hi CocInlayHint ctermbg=Black ctermfg=Gray +" +"set updatetime=300 +"set signcolumn=yes +" +"nmap [g (coc-diagnostic-prev) +"nmap ]g (coc-diagnostic-next) +" +"nmap gd (coc-definition) +"nmap gy (coc-type-definition) +"nmap gi (coc-implementation) +"nmap gr (coc-references) +" +"xmap f (coc-format-selected) +"nmap f (coc-format-selected) +" +"nmap rn (coc-rename) +"nmap re (coc-codeaction-refactor) +"xmap r (coc-codeaction-refactor-selected) +"" nmap r (coc-codeaction-refactor-selected) +" +"inoremap +" \ coc#pum#visible() ? coc#pum#next(1) : +" \ CheckBackspace() ? "\" : +" \ coc#refresh() +"inoremap coc#pum#visible() ? coc#pum#prev(1) : "\" +" +"inoremap coc#pum#visible() ? coc#pum#confirm() +" \: "\u\\=coc#on_enter()\" +" +"function! CheckBackspace() abort +" let col = col('.') - 1 +" return !col || getline('.')[col - 1] =~# '\s' +"endfunction +" +" +"if has('nvim') +" inoremap coc#refresh() +"else +" inoremap coc#refresh() +"endif +" +"xmap a (coc-codeaction-selected) +"nmap a (coc-codeaction-selected) +" +"" autocmd CursorHold * silent call CocActionAsync('highlight') +" +"function! ShowDocumentation() +" if CocAction('hasProvider', 'hover') +" call CocActionAsync('doHover') +" else +" call feedkeys('K', 'in') +" endif +"endfunction +" +"autocmd FileType python let b:coc_root_patterns = ['.git', '.env', '.'] + +Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' } +Plug 'junegunn/fzf.vim' -function! ShowDocumentation() - if CocAction('hasProvider', 'hover') - call CocActionAsync('doHover') - else - call feedkeys('K', 'in') - endif -endfunction -autocmd FileType python let b:coc_root_patterns = ['.git', '.env', '.'] +let g:fzf_cache_dir = '$HOME/.cache' -Plug 'junegunn/fzf.vim' +Plug 'yuki-yano/fzf-preview.vim' +Plug 'BurntSushi/ripgrep' nnoremap :Files nnoremap :Rg +nnoremap :Tags + +nnoremap g] :call fzf#vim#tags(expand('')) +nnoremap ag :Ag Plug 'heavenshell/vim-pydocstring', { 'do': 'make install', 'for': 'python' } @@ -123,9 +134,9 @@ Plug 'tpope/vim-fugitive' Plug 'yggdroot/indentline' -Plug 'yuttie/comfortable-motion.vim' -noremap :call comfortable_motion#flick(40) -noremap :call comfortable_motion#flick(-40) +"Plug 'yuttie/comfortable-motion.vim' +"noremap :call comfortable_motion#flick(40) +"noremap :call comfortable_motion#flick(-40) let g:comfortable_motion_interval = 2000.0/60 let g:comfortable_motion_friction = 80.0 @@ -141,3 +152,97 @@ highlight Pmenu ctermbg=black guibg=black ctermfg=white hi TrailingWhitespace ctermbg=red guibg=red call matchadd("TrailingWhitespace", '\v\s+$') + +" ex command for toggling hex mode - define mapping if desired +command -bar Hexmode call ToggleHex() + +" helper function to toggle hex mode +function ToggleHex() + " hex mode should be considered a read-only operation + " save values for modified and read-only for restoration later, + " and clear the read-only flag for now + let l:modified=&mod + let l:oldreadonly=&readonly + let &readonly=0 + let l:oldmodifiable=&modifiable + let &modifiable=1 + if !exists("b:editHex") || !b:editHex + " save old options + let b:oldft=&ft + let b:oldbin=&bin + " set new options + setlocal binary " make sure it overrides any textwidth, etc. + silent :e " this will reload the file without trickeries + "(DOS line endings will be shown entirely ) + let &ft="xxd" + " set status + let b:editHex=1 + " switch to hex editor + %!xxd + else + " restore old options + let &ft=b:oldft + if !b:oldbin + setlocal nobinary + endif + " set status + let b:editHex=0 + " return to normal editing + %!xxd -r + endif + " restore values for modified and read only state + let &mod=l:modified + let &readonly=l:oldreadonly + let &modifiable=l:oldmodifiable +endfunction + +" autocmds to automatically enter hex mode and handle file writes properly +if has("autocmd") + " vim -b : edit binary using xxd-format! + augroup Binary + au! + + " set binary option for all binary files before reading them + au BufReadPre *.bin,*.hex setlocal binary + + " if on a fresh read the buffer variable is already set, it's wrong + au BufReadPost * + \ if exists('b:editHex') && b:editHex | + \ let b:editHex = 0 | + \ endif + + " convert to hex on startup for binary files automatically + au BufReadPost * + \ if &binary | Hexmode | endif + + " When the text is freed, the next time the buffer is made active it will + " re-read the text and thus not match the correct mode, we will need to + " convert it again if the buffer is again loaded. + au BufUnload * + \ if getbufvar(expand(""), 'editHex') == 1 | + \ call setbufvar(expand(""), 'editHex', 0) | + \ endif + + " before writing a file when editing in hex mode, convert back to non-hex + au BufWritePre * + \ if exists("b:editHex") && b:editHex && &binary | + \ let oldro=&ro | let &ro=0 | + \ let oldma=&ma | let &ma=1 | + \ silent exe "%!xxd -r" | + \ let &ma=oldma | let &ro=oldro | + \ unlet oldma | unlet oldro | + \ endif + + " after writing a binary file, if we're in hex mode, restore hex mode + au BufWritePost * + \ if exists("b:editHex") && b:editHex && &binary | + \ let oldro=&ro | let &ro=0 | + \ let oldma=&ma | let &ma=1 | + \ silent exe "%!xxd" | + \ exe "set nomod" | + \ let &ma=oldma | let &ro=oldro | + \ unlet oldma | unlet oldro | + \ endif + augroup END +endif + diff --git a/mkshrc b/mkshrc index 6f56079..7d91528 100644 --- a/mkshrc +++ b/mkshrc @@ -7,7 +7,7 @@ esac export VIMINIT="source ~/.config/vim/vimrc" export NVIMINIT="source ~/.config/vim/vimrc" -HISTFILE="$HOME/.mksh_history" +HISTFILE="/tmp/.mksh_history$$" HISTSIZE=5000 if [ -x /usr/bin/dircolors ]; then diff --git a/scripts/toggle-mic.sh b/scripts/toggle-mic.sh new file mode 100755 index 0000000..d3e3244 --- /dev/null +++ b/scripts/toggle-mic.sh @@ -0,0 +1,4 @@ +#!/bin/sh +SOURCE=1 +pactl list sources | grep -qi 'Mute: yes' && pactl set-source-mute $SOURCE false || pactl set-source-mute $SOURCE true + diff --git a/scripts/xrandr.sh b/scripts/xrandr.sh new file mode 100755 index 0000000..1827cd7 --- /dev/null +++ b/scripts/xrandr.sh @@ -0,0 +1,35 @@ +#!/bin/sh +all=$(xrandr | grep "connected" | cut -d' ' -f1 | paste -s -d' ') +available=$(xrandr | grep " connected" | cut -d' ' -f1 | paste -s -d' ') +set -- $available + +printf "connected: " +printf "%s " $available +printf "\n" + +printf "all: " +printf "%s " $all +printf "\n" + +if [ "$1" == "eDP1" ]; then + # this is a laptop so awesome! + + if [ "$#" != "1" ]; then + # ensure the main one is turned on yeah + xrandr --output eDP1 --mode 1920x1080 --pos 0x0 --rotate normal + + # put the non main one to the left (assume its +1920 because im lazy) + xrandr --output "$2" --primary --mode 2560x1440 --pos 1920x0 --rotate normal + else + # ensure the main one is turned on yeah + xrandr --output eDP1 --primary --mode 1920x1080 --pos 0x0 --rotate normal + fi + #disconnect all the rest i think + for x in $all; do + echo disconnecting $x + case $available in + *"$x"*) ;; + *) xrandr --output "$x" --off + esac + done +fi -- cgit v1.2.3