Dotfiles - bash/vim
Some dotfiles can be found here .
Intro
There are many ways to configure bash/vim setups, but it should not be done not knowing
what commands are being set (so don’t do it blindly, consult a man
page ).
Bash
One easy way to have a custom bash
aliases is to use a
~/.bash_aliases
file, as the main .bashrc should call it once done setting up the bash
prompt. One great alias is "cd $(ls -td path/to/folder/*/ | head -1)"
, which goes to the
last modified folder.
.bash_aliases
# Modifications - Commands when opening new terminal
PROMPT_DIRTRIM = 3 # only show 3 directories
export PYTHONUSERBASE = $HOME /.local
export PATH = $PATH :$( pwd ) :$HOME /.local/bin:$( ruby -e 'puts Gem.user_dir' ) /bin
export QUOTING_STYLE = literal #changes ls so no 'name space'
export PROMPT_COMMAND = 'history -a' #multiple terminals, save history
export HISTSIZE = 1000 #save more history
HISTCONTROL = ignoredups #ignore duplicates
#alias svr="ssh -X user@host.com"
#go to most recently used folder
alias atmega = "cd $( ls -td ~/Documents/Projects/Atmega328/* / | head -1 ) "
#avoid atmega directory
alias project = "cd $( ls -td -I "Atmega328/" ~/Documents/Projects/* / | head -1 ) "
alias hg = "history | grep " #search history
stty -ixon #stop terminal freezes
set bell-style none #no bell
shopt -s checkwinsize #proper window checking
shopt -s autocd #cd dir with name
Vim
Basic vim can be hard to use at times, but adding certain options can make it easier to
use. The .vimrc file below
contains the current options that can be used, along with comments about what each line
does.
One way to extend vim is with plugins , along with
using vim fugitive for git and vim
airline for making vim look better.
Vim can redo a previous command with q:
, and then in insert mode (i
) can edit and then
with enter
run the command.
One easy way to reformat markdown files is to set textwidth=80
, highlight lines
(Shift+V
), and then use gq
to format to that textwidth.
Also helpful is spellcheck that can be toggled with ,s
and then use \s
to show
suggestions.
.vimrc
" => General
syntax on " Syntax highlighting
filetype plugin indent on "auto determine file type & plugin
set lazyredraw " redraw only when necessary
let mapleader = ","
set t_Co = 256 "Set color to 256
" => User Interface
colorscheme elflord
set background = dark "Tells vim that the background is dark
set showmatch " Show matching braces
set showmode "Show current mode
set wildmenu " better cmd-line completion
set showcmd "show partial commands
set mouse=r " Enable mouse a = all, v = visual, n = normal
set number "set line numbers
set noerrorbells " no sound on error
set clipboard = unnamedplus,autoselect "clipboard
set display+=uhex " show unprintable chars as hex number
"clipboard support in visual mode
vmap <leader>y " +y
vmap <leader>p "+p
" Stop q: shortcut menu
map q: :q
" => plugins
call plug#begin('~/.vim/plugged')
Plug 'tpope/vim-fugitive' " For git plugins for vim-airline
Plug 'vim-airline/vim-airline' "For pretty colors
Plug 'stevearc/vim-arduino' " For arduino stuff
call plug#end()
" Airline
let g:airline_left_sep = ''
let g:airline_right_sep = ''
let g:airline#extensions#tabline#enabled = 1
set noshowmode " hide bottom column
"save workspace
nnoremap sw :mksession! ~/.vim/work.vim
nnoremap rw :source! ~/.vim/work.vim
nnoremap sr :mksession! ~/.vim/ref.vim
nnoremap rr :source! ~/.vim/ref.vim
" switch buffers
nnoremap <silent> <tab> :if &modifiable && ! &readonly && &modified <CR> :write<CR> :endif<CR>:bnext<CR>
nnoremap <silent> <s-tab> :if &modifiable && ! &readonly && &modified <CR> :write<CR> :endif<CR>:bprevious<CR>
" => Search
set incsearch " Incremental search
set hlsearch "Highlight search
set ignorecase " Ignore case in searching
"Turn off search hightlight with ,<space>
nnoremap <leader><space> :nohlsearch<CR>
" highlight extra spaces
highligh ExtraWhitespace ctermbg = darkgreen guibg = darkgreen
match ExtraWhitespace /\s\+ $/
" => Replacement
" When one of the chars is typed, the matching is typed and the cursor moves left
"inoremap ' ''<left>
" inoremap \" \" "<left>
inoremap { {}<left>
inoremap ( ()<left>
inoremap [ []<left>
set expandtab " Spaces instead of tabs
set shiftwidth = 4 "1 tab = 4 spaces
set tabstop=4
set softtabstop=4
autocmd VimEnter * fixdel
set backspace=indent,eol,start " Fix backspace
" turn off page up/down
noremap <PageUp> <nop>
inoremap <PageUp> <nop>
nnoremap <PageUp> <nop>
noremap <PageDown> <nop>
inoremap <PageDown> <nop>
nnoremap <PageDown> <nop>
set textwidth=90 " In comments wrap at 90 chars, use gg, gqG, or shift +v lines and gq
set wrapmargin = 2
set tags = ./tags; ,tags; ./.tags; ,.tags;
" => Spellcheck
" toggle with ,s, ] s fwd, [ s bkwd, z = OR \s shows suggestions, zg adds word, zw removes
nmap <silent> <leader>s :set spell!<CR>
set spelllang = en_us "Region
nnoremap \s a<C-X><C-S>
" Resize text
command ! TF :call Textflow( )
function ! Textflow()
:normal ggVG
:normal gq
endfunction
Other helpful guides include sheerun’s and others.
i3 WM
i3 windows manager is a tiling windows manager, where most of the actions are controlled
from the keyboard. The major advantage is that default programs need to be started
specifically before being used.
The config file
contains all the information used to setup i3. This config is setup for a Thinkpad T440s
and its keyboard hotkeys, so everything might not work on a different machine. Additions
to the config file include starting up NetworkManager, redshift (for a color shift),
notifications, and an service for calling a GUI sudo (for mounting drives). Other
additions include media buttons, a power menu, brightness control, and changing sleep
settings.
The only major downside is working with programs that are not built for tiling windows
managers, like some virtual machines or software like KiCad. The setup can be awkward, but
still work.
config
# i3 config file (v4)
# Please see http://i3wm.org/docs/userguide.html for a complete reference!
set $mod Mod4
set $mod1 Mod1
#Alt is Mod1
##############
# My changes #
##############
#Terminal - originally i3-sensible-terminal
set $i3Term konsole
set $i3Dir ~/.config/i3
exec --no-startup-id compton $i3dir /compton.conf
exec --no-startup-id /usr/lib/geoclue-2.0/demos/agent #for redshift
exec_always --no-startup-id pkill -f -o lxqt-notificationd #kill last process, for reload
exec_always --no-startup-id lxqt-notificationd #need for nm-applet, else hang
exec --no-startup-id lxqt-policykit-agent #for sudo access
exec --no-startup-id nm-applet #networking
exec --no-startup-id redshift-gtk
exec_always --no-startup-id feh --bg-fill ~/Pictures/Wallpapers/CurrentWallpaper.jpg
#Touchpad/keyboard onfig
exec --no-startup-id $i3Dir /touchpad.sh #touchpad config
exec --no-startup-id setxkbmap -option ctrl:nocaps
exec --no-startup-id xmodmap $i3Dir /Oldfiles/xmodmap
exec --no-startup-id xbacklight -set 1
#Custom Keybinds
bindsym Control+$mod +c exec google-chrome --profile-directory = "Default" #stable
bindsym Control+$mod +i exec google-chrome --incognito --profile-directory = "Default"
bindsym Control+$mod +h exec google-chrome --profile-directory = "Profile 1"
bindsym Control+$mod +Shift+i exec google-chrome --incognito --profile-directory = "Profile 1"
bindsym Control+$mod +f exec pcmanfm-qt
bindsym Control+$mod +s exec qps
bindsym Control+$mod +t exec $i3Term
bindsym Control+$mod +x exec env MOZ_USE_XINPUT2 = 1 firefox
bindsym Control+$mod +z exec env MOZ_USE_XINPUT2 = 1 firefox -private
bindsym Control+$mod +w exec libreoffice --writer
bindsym --release Shift+Print exec gnome-screenshot -a -i
set $Displays External Displays: ( B) oth ( M) irror ( D) isplayPort ( V) GA ( a) randr ( o) ff
mode " $Displays " {
bindsym b exec --no-startup-id $i3Dir /screen.sh b, mode "default"
bindsym m exec --no-startup-id $i3Dir /screen.sh m, mode "default"
bindsym d exec --no-startup-id $i3Dir /screen.sh d, mode "default"
bindsym v exec --no-startup-id $i3Dir /screen.sh v, mode "default"
bindsym o exec --no-startup-id $i3Dir /screen.sh o, mode "default"
bindsym a exec arandr, mode "default"
bindsym Escape mode "default"
bindsym Return mode "default"
}
bindsym $mod +p mode " $Displays "
#Function Buttons
bindsym Control+$mod +F12 exec --no-startup-id xinput enable 10
bindsym Control+$mod +Shift+F12 exec --no-startup-id xinput disable 10
#Pulse Audio controls - find with 'xmodmap -pk | grep -i XF86'
bindsym XF86AudioMute exec --no-startup-id pactl set-sink-mute 0 toggle #mute sound
bindsym XF86AudioLowerVolume exec --no-startup-id pactl set-sink-volume 0 -1 % #dec volume
bindsym Shift+XF86AudioLowerVolume exec --no-startup-id pactl set-sink-volume 0 -5 %
bindsym XF86AudioRaiseVolume exec --no-startup-id pactl set-sink-volume 0 +1% # inc volume
bindsym Shift+XF86AudioRaiseVolume exec --no-startup-id pactl set-sink-volume 0 +5% #
#Screen brightness controls - xbacklight -inc/-dec 1
bindsym XF86MonBrightnessUp exec --no-startup-id $i3Dir /backlight.sh i 1 #inc scr bright %
bindsym Shift+XF86MonBrightnessUp exec --no-startup-id $i3Dir /backlight.sh i 5
bindsym XF86MonBrightnessDown exec --no-startup-id $i3Dir /backlight.sh d 1 #dec scr bright %
bindsym Shift+XF86MonBrightnessDown exec --no-startup-id $i3Dir /backlight.sh d 5
bindsym $mod +Shift+b exec --no-startup-id xbacklight -set 1
#floating - xprop
bindsym $mod +Shift+space floating toggle
#bindsym Control+$mod+Shift+1 [class="^.*"] border toggle
for_window [ class = "^.*" ] border pixel 0
for_window [ class = "Nm-connection-editor" ] floating enable
for_window [ window_role = "pop-up" ] floating enable
for_window [ window_role = "task_dialog" ] floating enable
#for_window [workspace="20"] floating enable
#Shutdown, reboot, etc
set $Locker i3lock --color = 006221 --ignore-empty-password --show-failed-attempts && sleep 0.1
exec --no-startup-id xss-lock --transfer-sleep-lock -- $Locker && systemctl suspend #autolock
#change suspend time (900s = 15 min), s = screensaver, xset q = query
exec --no-startup-id xset s 900 930
#dpms = disp pwr mgmt, standby, suspend, off
exec --no-startup-id xset dpms 910 920 930
#(s) suspend
set $SystemPower ( e) xit, ( h) ibernate, ( L,o) ck, ( p) ower off, ( r) eboot
mode " $SystemPower " {
bindsym e exec --no-startup-id i3-msg exit , mode "default"
bindsym shift +l exec --no-startup-id $Locker && systemctl suspend , mode "default"
bindsym o exec --no-startup-id $Locker && systemctl suspend , mode "default"
bindsym h exec --no-startup-id $Locker && systemctl hibernate, mode "default"
bindsym r exec --no-startup-id systemctl reboot, mode "default"
bindsym p exec --no-startup-id systemctl poweroff, mode "default"
# back to normal: Enter or Escape
bindsym Return mode "default"
bindsym Escape mode "default"
}
bindsym Control+$mod1 +l mode " $SystemPower "
bindsym $mod +l mode " $SystemPower "
#################################
# Default Config stuff #
#################################
# Font for window titles. Will also be used by the bar unless a different font
# is used in the bar {} block below.
# This font is widely installed, provides lots of unicode glyphs, right-to-left
# text rendering and scalability on retina/hidpi displays (thanks to pango).
font pango:DejaVu Sans Mono 8
# Before i3 v4.8, we used to recommend this one as the default:
# font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
# The font above is very space-efficient, that is, it looks good, sharp and
# clear in small sizes. However, its unicode glyph coverage is limited, the old
# X core fonts rendering does not support right-to-left and this being a bitmap
# font, it doesn’t scale on retina/hidpi displays.
# Use Mouse+$mod to drag floating windows to their wanted position
floating_modifier $mod
# start a terminal
bindsym $mod +Return exec $i3Term
# kill focused window
bindsym $mod +Shift+q kill
# start dmenu (a program launcher)
#bindsym Control+$mod+d exec dmenu_run
# There also is the (new) i3-dmenu-desktop which only displays applications
# shipping a .desktop file. It is a wrapper around dmenu, so you need that
# installed.
#bindsym $mod+d exec --no-startup-id i3-dmenu-desktop
#j4 menu is faster :)
bindsym $mod +d exec --no-startup-id j4-dmenu-desktop
#thinkpad search key, find with xev
bindsym XF86Search exec synapse
# change focus
bindsym $mod +Left focus left
bindsym $mod +Down focus down
bindsym $mod +Up focus up
bindsym $mod +Right focus right
# move focused window
bindsym $mod +Shift+Left move left
bindsym $mod +Shift+Down move down
bindsym $mod +Shift+Up move up
bindsym $mod +Shift+Right move right
# split in horizontal orientation
bindsym $mod +h split h
# split in vertical orientation
bindsym $mod +v split v
# enter fullscreen mode for the focused container
# bindsym $mod+f fullscreen
# change container layout (stacked, tabbed, toggle split)
#bindsym $mod+s layout stacking
#bindsym $mod+w layout tabbed
bindsym $mod +e layout toggle split
# toggle tiling / floating
#bindsym $mod+Shift+space floating toggle
bindsym $mod +shift+f floating toggle
# change focus between tiling / floating windows
#bindsym $mod+space focus mode_toggle
bindsym $mod +f focus mode_toggle
# focus the parent container
bindsym $mod +a focus parent
# focus the child container
#bindsym $mod+d focus child
# switch to workspace
bindsym $mod +1 workspace 1
bindsym $mod +2 workspace 2
bindsym $mod +3 workspace 3
bindsym $mod +4 workspace 4
bindsym $mod +5 workspace 5
bindsym $mod +6 workspace 6
bindsym $mod +7 workspace 7
bindsym $mod +8 workspace 8
bindsym $mod +9 workspace 9
bindsym $mod +0 workspace 10
bindsym $mod1 +1 workspace 11
bindsym $mod1 +2 workspace 12
bindsym $mod1 +3 workspace 13
bindsym $mod1 +4 workspace 14
bindsym $mod1 +5 workspace 15
bindsym $mod1 +6 workspace 16
bindsym $mod1 +7 workspace 17
bindsym $mod1 +8 workspace 18
bindsym $mod1 +9 workspace 19
bindsym $mod1 +0 workspace 20
# switch via tab
bindsym $mod +Tab workspace next
bindsym $mod +Shift+Tab workspace prev
# move focused container to workspace
bindsym $mod +Shift+1 move container to workspace 1
bindsym $mod +Shift+2 move container to workspace 2
bindsym $mod +Shift+3 move container to workspace 3
bindsym $mod +Shift+4 move container to workspace 4
bindsym $mod +Shift+5 move container to workspace 5
bindsym $mod +Shift+6 move container to workspace 6
bindsym $mod +Shift+7 move container to workspace 7
bindsym $mod +Shift+8 move container to workspace 8
bindsym $mod +Shift+9 move container to workspace 9
bindsym $mod +Shift+0 move container to workspace 10
bindsym $mod1 +Shift+1 move container to workspace 11
bindsym $mod1 +Shift+2 move container to workspace 12
bindsym $mod1 +Shift+3 move container to workspace 13
bindsym $mod1 +Shift+4 move container to workspace 14
bindsym $mod1 +Shift+5 move container to workspace 15
bindsym $mod1 +Shift+6 move container to workspace 16
bindsym $mod1 +Shift+7 move container to workspace 17
bindsym $mod1 +Shift+8 move container to workspace 18
bindsym $mod1 +Shift+9 move container to workspace 19
bindsym $mod1 +Shift+0 move container to workspace 20
# reload the configuration file
bindsym $mod +Shift+c reload
# restart i3 inplace (preserves your layout/session, can be used to upgrade i3)
bindsym $mod +Shift+r restart
# exit i3 (logs you out of your X session)
#bindsym $mod+Shift+e exec "i3-nagbar -t warning -m 'You pressed the exit shortcut. Do you really want to exit i3? This will end your X session.' -b 'Yes, exit i3' 'i3-msg exit'"
# resize window (you can also use the mouse for that)
mode "resize" {
# These bindings trigger as soon as you enter the resize mode
bindsym Left resize shrink width 10 px or 10 ppt
bindsym Down resize grow height 10 px or 10 ppt
bindsym Up resize shrink height 10 px or 10 ppt
bindsym Right resize grow width 10 px or 10 ppt
# back to normal: Enter or Escape
bindsym Return mode "default"
bindsym Escape mode "default"
}
bindsym $mod +r mode "resize"
# Start i3bar to display a workspace bar (plus the system information i3status
# finds out, if available)
bar {
position top
workspace_buttons yes
tray_output primary
status_command i3status --config ~/.config/i3/status.conf
}
Rsync
When syncing between two machines, rsync can be nice as it can include/exclude files from
a file, and only copy changed files.
copy.sh (example)
#!/bin/bash
files =( ~/.vimrc ~/.config/i3/{ config,touchpad.sh})
for i in ${ files [@] } ; do
echo "cp $i to ."
cp " $i " .
done
include/exclude
copy_include
+ file.ext
+ folder/
+ folder/file.ext
- *
copy_exclude
* .sw*
Git
Git is a pretty good source control manager, and can be used locally (without GitHub) if
necessary. It is also suggested if using vim to use vim-fugitive to display the current
branch.
Git/Github/Gitlab and others in the software community are now suggesting changing
the default name of repositories to ‘main’. For GitHub, follow the directions
here and below (after it is renamed):
git branch -m master main
git fetch origin
git branch -u origin/main main
git remote set-head origin -a (optional)
Makefiles
Makefiles are
handy
resources
when compiling code with not much complexity, as there are better tools for larger
projects. However, for things like
microcontrollers or repeated
actions makefiles can be nice to have.
In makefiles, =
sets the variable when it is used, and :=
sets the variable when first
initialized. For commands in rules that begin with -
means that the rule won’t fail if
that command fails. If a command goes to the next line, it can be broken up with \
to
seperate the command but keep it as one command.
Some automatic variables that are nice to know include $@
for the file name in the rule
target, $<
for the name of the first prerequisite, $?
for newer files of
prerequisites, and $^
for the name of all of the prerequisites.
It can also be nice to remove files with a clean
rule like -rm -rf file *.ext
. Another
use is to zip/tar files with a command (for uploading files). If using
zip , the command could be zip -u zipfile.zip files...
|| true
where -u is update. For tar ,
an example could be tar -u -v -f file.tar files...
where -u
is --update
, -v
is
--verbose
, and -f
is --file
.
More program hints can be found in Linux Troubleshooting