DotfilesΒΆ

Some of my dotfiles

bash
00-options

shopt -s autocd         # If no command found, but matches a directory, cd into it
shopt -s checkjobs      # Warn about background jobs before exiting
shopt -s checkwinsize   # Update the COLUMNS and LINES environment variables between each command
shopt -s extglob        # Enable extended pattern matching features
shopt -s globstar       # Enable recursive globbing i.e `./**/*.py`

[ -d "$HOME/Projects" ] && export CDPATH=".:~/Projects"

paths=(
    "$HOME/go/bin"
    "$HOME/.cargo/bin"
    "$HOME/.npm-packages/bin"
)

for p in ${paths[@]}
do
    [ -d $p ] && export PATH="$p:$PATH"
done

shopt -s histappend

HISTCONTROL=erasedups
HISTFILESIZE=100000
HISTIGNORE='cd:ls'
HISTSIZE=10000
10-aliases

alias ls='ls -CFhX --color=auto --group-directories-first'
alias pypath='echo $PYTHONPATH | tr '\'':'\'' '\''\n'\'''
20-prompt

__venv_py_version()
{
    if [ -z "${VIRTUAL_ENV}" ]; then
        echo ""
    else
        echo " 🐍 v$(python --version | sed 's/Python //')"
    fi
}

__is_toolbox()
{
    if [ -f /run/.containerenv ] && [ -f /run/.toolboxenv ]; then
        name=$(grep name /run/.containerenv | sed 's/.*"\(.*\)"/\1/')

    else
        name="\h"
    fi

    echo "\[\e[32m\]${name}\[\e[0m\]"
}

if [ -f "/usr/share/git-core/contrib/completion/git-prompt.sh" ]; then
    source "/usr/share/git-core/contrib/completion/git-prompt.sh"

    export GIT_PS1_SHOWDIRTYSTATE=1       # (*) unstaged changes, (+) staged changes
    export GIT_PS1_SHOWSTASHSTATE=1       # ($) stashed
    export GIT_PS1_SHOWUNTRACKEDFILES=1   # (%) untracked files
    export GIT_PS1_SHOWUPSTREAM=verbose
    export GIT_PS1_SHOWCOLORHINTS=1

    export PROMPT_COMMAND='__git_ps1 "\n\w " "$(__venv_py_version)\n$(__is_toolbox) > " "[ξ‚  %s]"'
else
    export PS1="\W\n> "
fi
jj
config.toml

"$schema" = "https://jj-vcs.github.io/jj/latest/config-schema.json"

user.name = "Alex Carney"
user.email = "alcarneyme@gmail.com"

ui.editor = "emacsclient"

ui.default-command = "status"

ui.conflict-marker-style = "git"
ui.diff-formatter = ":git"

[aliases]
push-down = ["new", "-B", "@", "--no-edit"]
nvim
lua
alc
lsp
esbonio.lua

function setup(opts)
   opts = opts or {}

   if not opts.capabilities then
     opts.capabilities = vim.lsp.protocol.make_client_capabilities()
   end

   require('lspconfig').esbonio.setup {
     cmd = get_esbonio_cmd(opts),
     capabilities = capabilities,
     handlers = {
       ["sphinx/clientCreated"] = client_created,
       ["sphinx/appCreated"] = app_created,
       ["sphinx/clientErrored"] = client_errored,
       ["sphinx/clientDestroyed"] = client_destroyed,
     },
     commands = {
       EsbonioPreviewFile = {
         preview_file,
         description = 'Preview Current File',
       },
     },
     settings = {
       esbonio = {
         logging = {
           level = 'debug',
           window = opts.devtools or false,
         }
       }
     }
   }
end

function get_esbonio_cmd(opts)
  local cmd = {}

  -- TODO: Devcontainer support.
  --
  -- local workspace = require('alc.devcontainer').workspace()
  -- if workspace then
  --   table.insert(cmd, 'devcontainer')
  --   table.insert(cmd, 'exec')
  --   table.insert(cmd, '--workspace-folder')
  --   table.insert(cmd, workspace)
  -- end

  if opts.devtools then
    table.insert(cmd, 'lsp-devtools')
    table.insert(cmd, 'agent')
    table.insert(cmd, '--')
  end

  table.insert(cmd, 'esbonio')
  return cmd
end

function preview_file()
  local params = {
    command = 'esbonio.server.previewFile',
    arguments = {
      { uri = vim.uri_from_bufnr(0), show = true },
    },
  }

  local clients = require('lspconfig.util').get_lsp_clients {
    bufnr = vim.api.nvim_get_current_buf(),
    name = 'esbonio',
  }
  for _, client in ipairs(clients) do
    client.request('workspace/executeCommand', params, nil, 0)
  end

  local augroup = vim.api.nvim_create_augroup("EsbonioSyncScroll", { clear = true })
  vim.api.nvim_create_autocmd({"WinScrolled"}, {
    callback = scroll_view, group = augroup, buffer = 0
  })
end

function scroll_view(event)
  local esbonio = vim.lsp.get_active_clients({ bufnr = 0, name = 'esbonio' })[1]
  local view = vim.fn.winsaveview()

  local params = { uri = vim.uri_from_bufnr(0),  line = view.topline }
  esbonio.notify('view/scroll', params)
end

function client_created(err, result, ctx, config)
  vim.notify("Sphinx client created in " .. result.scope, vim.log.levels.INFO)
end

function app_created(err, result, ctx, config)
  vim.notify("Application created", vim.log.levels.INFO)
end

function client_errored(err, result, ctx, config)
  vim.notify("Client error: " .. result.error, vim.log.levels.ERROR)
end

function client_destroyed(err, result, ctx, config)
  vim.notify("Sphinx client destroyed", vim.log.levels.INFO)
end

return {
  setup = setup
}
init.lua

function lsp_attach(event)
  vim.keymap.set('n', 'gd', require('telescope.builtin').lsp_definitions, { buffer = event.buf })
  vim.keymap.set('n', 'gr', require('telescope.builtin').lsp_references, { buffer = event.buf })
  vim.keymap.set('n', 'gI', require('telescope.builtin').lsp_implementations, { buffer = event.buf })
  vim.keymap.set('n', '<leader>D', require('telescope.builtin').lsp_type_definitions, { buffer = event.buf })
  vim.keymap.set('n', '<leader>ds', require('telescope.builtin').lsp_document_symbols, { buffer = event.buf })
  vim.keymap.set('n', '<leader>ws', require('telescope.builtin').lsp_dynamic_workspace_symbols, { buffer = event.buf })
  vim.keymap.set('n', '<leader>rn', vim.lsp.buf.rename, { buffer = event.buf })
  vim.keymap.set('n', '<leader>ca', vim.lsp.buf.code_action, { buffer = event.buf })
  vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, { buffer = event.buf })
end

return {
   'neovim/nvim-lspconfig',
   dependencies = {
     'hrsh7th/cmp-nvim-lsp',
     { 'j-hui/fidget.nvim', opts = {
         notification = {
           override_vim_notify = true,
         }
       }
     },
   },
   config = function()
     vim.api.nvim_create_autocmd('LspAttach', {
       group = vim.api.nvim_create_augroup('alc-lsp-attach', { clear = true }),
       callback = lsp_attach
     })

     -- Ensure the additional capabilities provided by nvim-cmp are provided to the server
     local capabilities = vim.lsp.protocol.make_client_capabilities()
     capabilities = vim.tbl_deep_extend('force', capabilities, require('cmp_nvim_lsp').default_capabilities())

     -- Setup each server
     local use_devtools = os.getenv('LSP_DEVTOOLS') ~= nil
     require('alc.lsp.esbonio').setup { capabilities = capabilities, devtools = use_devtools }
     require('alc.lsp.python').setup { capabilities = capabilities }
   end
}
python.lua

function setup(opts)
   opts = opts or {}

   if not opts.capabilities then
     opts.capabilities = vim.lsp.protocol.make_client_capabilities()
   end

   require('lspconfig').pyright.setup {
     capabilities = capabilities,
     settings = {
       python = {
       }
     }
   }
end

return {
  setup = setup
}
completion.lua

function setup()
  local cmp = require('cmp')

  cmp.setup {
    completion = { completeopt = 'menu,menuone,noinsert' },
    mapping = cmp.mapping.preset.insert {
       ['<C-n>'] = cmp.mapping.select_next_item(),
       ['<C-p>'] = cmp.mapping.select_prev_item(),
       ['<C-b>'] = cmp.mapping.scroll_docs(-4),
       ['<C-f>'] = cmp.mapping.scroll_docs(4),
       ['<C-y>'] = cmp.mapping.confirm { select = true },
     },
    sources = {
       { name = 'nvim_lsp' },
     },
  }
end

return {
  'hrsh7th/nvim-cmp',
  event = 'InsertEnter',
  dependencies = {
    'hrsh7th/cmp-nvim-lsp',
  },
  config = setup
}
devcontainer.lua

function workspace()
  local cwd = vim.uv.cwd()
  if not cwd then
    return nil
  end

  local repo = require('lspconfig.util').find_git_ancestor(cwd)
  if not repo then
    return nil
  end

  local devcontainer = vim.fs.joinpath(repo, '.devcontainer')
  if not vim.uv.fs_stat(devcontainer) then
    return nil
  end

  return repo
end

return {
  workspace = workspace
}
telescope.lua

return {
  'nvim-telescope/telescope.nvim',
  event = 'VimEnter',
  branch = '0.1.x',
  dependencies = {
    'nvim-lua/plenary.nvim',
    'nvim-telescope/telescope-ui-select.nvim',
  },
  config = function()
    local themes = require('telescope.themes')

    require('telescope').setup {
      defaults = themes.get_ivy(opts)
    }

    pcall(require('telescope').load_extension, 'ui-select')

    local builtin = require 'telescope.builtin'
    vim.keymap.set('n', '<leader>ff', builtin.find_files)
  end
}
init.lua

vim.opt.termguicolors = false

vim.opt.breakindent = true

vim.opt.inccommand = 'split'
vim.opt.incsearch = true
vim.opt.ignorecase = false

vim.opt.number = true

vim.opt.signcolumn = 'number'

vim.opt.list = true
vim.opt.listchars = { tab = 'Β».', trail = 'Β·', extends = 'β†’', precedes= '←' }

vim.g.mapleader = ' '
vim.g.maplocalleader = ' '

vim.keymap.set('n', '<Esc>', '<cmd>nohlsearch<CR>')

vim.keymap.set('n', '<C-h>', '<C-w><C-h>')
vim.keymap.set('n', '<C-l>', '<C-w><C-l>')
vim.keymap.set('n', '<C-j>', '<C-w><C-j>')
vim.keymap.set('n', '<C-k>', '<C-w><C-k>')

vim.keymap.set('n', 'n', 'nzz')
vim.keymap.set('n', 'N', 'Nzz')
vim.keymap.set('n', 'G', 'Gzz')
vim.keymap.set('n', '<c-i>', '<c-i>zz')
vim.keymap.set('n', '<c-o>', '<c-o>zz')

local lazypath = vim.fn.stdpath('data') .. '/lazy/lazy.nvim'
if not vim.uv.fs_stat(lazypath) then
  local lazyrepo = 'https://github.com/folke/lazy.nvim.git'
  local out = vim.fn.system({ 'git', 'clone', '--filter=blob:none', '--branch=stable', lazyrepo, lazypath})

  if vim.v.shell_error ~= 0 then
    error('Error cloning lazy.nvim:\n' .. out)
  end
end

vim.opt.rtp:prepend(lazypath)

require('lazy').setup({
  'tpope/vim-sleuth',
  require 'alc.completion',
  require 'alc.lsp',
  require 'alc.telescope',
})
vscode
settings.json

{

"window.autoDetectColorScheme": true,
"workbench.preferredLightColorTheme": "GitHub Light Default",
"workbench.preferredDarkColorTheme": "GitHub Dark Dimmed",

"workbench.iconTheme": "material-icon-theme",

"editor.fontFamily": "'UbuntuMono NF', 'monospace', monospace",
"editor.fontSize": 12,
"editor.fontLigatures": true,
"terminal.integrated.fontFamily": "'Ubuntu Mono NF', 'monospace', monospace",
"terminal.integrated.fontSize": 12,
"terminal.integrated.lineHeight": 1,

"editor.cursorStyle": "block",
"editor.cursorBlinking": "solid",
"editor.cursorSmoothCaretAnimation": "on",
"editor.minimap.enabled": false,
"editor.smoothScrolling": true,
"debug.toolBarLocation": "commandCenter",
"window.commandCenter": true,
"window.titleBarStyle": "custom",
"workbench.activityBar.location": "top",
"workbench.editor.showTabs": "single",
"workbench.layoutControl.enabled": true,
"workbench.list.smoothScrolling": true,

"files.autoSave": "off",
"files.enableTrash": false,
"files.insertFinalNewline": true,
"files.trimTrailingWhitespace": true,
"files.trimFinalNewlines": true,

"files.exclude": {
   "**/.hg": true,
   "**/.git": true,
   "**/.svn": true,
   "**/*.pyc": true,
   "**/.mypy_cache": true,
   "**/__pycache__": true,
},

"[python]": {
  "editor.rulers": [ 89 ]
},

"[restructuredtext]": {
  "editor.tabSize": 3,
  "editor.wordBasedSuggestions": "off",
},

}
wezterm
commands
screenshot.lua

local wezterm = require 'wezterm'
local io = require 'io'
local os = require 'os'
local act = wezterm.action

local M = {}

local function append_tables(...)
 local result = {}
 for _, tbl in ipairs({...}) do
     for i = 1, #tbl do
         result[#result + 1] = tbl[i]
     end
 end
 return result
end

function M.setup()

  wezterm.on('augment-command-palette', function(window, pane)
    return {
      {
        brief = 'Take screenshot',
        icon = 'cod_device_camera',

        action = act.PromptInputLine {
          description = 'Screenshot name',
          -- initial_value = os.date('%Y%m%dT%H%M%S--terminal-screenshot'), -- apparently this requires a nightly build
          action = wezterm.action_callback(function(window, pane, line)
            if line then
              local dimensions = pane:get_dimensions()
              local theme = wezterm.get_builtin_color_schemes()[window:effective_config().color_scheme]
              local body = {0, "o", pane:get_lines_as_escapes()}

              local header = {
                version = 3,
                term = {
                  cols = dimensions.cols,
                  rows = dimensions.viewport_rows,
                  theme = {
                    fg = theme.foreground,
                    bg = theme.background,
                    palette = table.concat(append_tables(theme.ansi, theme.brights), ':'),
                  },
                },
              }

              local f = io.open(line .. '.cast', 'w+')
              f:write(wezterm.json_encode(header) .. '\n')
              f:write(wezterm.json_encode(body))
              f:flush()
              f:close()
            end
          end),
        },
      },
    }
  end)
end

return M
wezterm.lua

local wezterm = require 'wezterm'
local config = wezterm.config_builder()
config.keys = {}

config.font = wezterm.font('UbuntuMono Nerd Font')

if wezterm.gui.get_appearance():find("Dark") then
  config.color_scheme = 'Modus-Vivendi'
else
  config.color_scheme = 'Modus-Operandi'
end

config.use_fancy_tab_bar = true

config.default_prog = { '/usr/bin/fish', '-l' }

table.insert(config.keys, {
  key = 'Enter', mods = 'ALT', action = wezterm.action.DisableDefaultAssignment,
})

local screenshot_command = require 'commands.screenshot'
screenshot_command.setup()

return config
Makefile

.PHONY: wezterm
wezterm:
     test -L $(HOME)/.config/wezterm || ln -s $(shell pwd)/wezterm $(HOME)/.config/wezterm

.PHONY: bash
bash:
     test -L $(HOME)/.bash_profile || ln -s $(shell pwd)/bash_profile $(HOME)/.bash_profile
     test -L $(HOME)/.bashrc || ln -s $(shell pwd)/bashrc $(HOME)/.bashrc
     test -L $(HOME)/.bashrc.d || ln -s $(shell pwd)/bash $(HOME)/.bashrc.d

.PHONY: git
git:
     test -L $(HOME)/.gitconfig || ln -s $(shell pwd)/gitconfig $(HOME)/.gitconfig

.PHONY: nvim
nvim:
     test -L $(HOME)/.config/nvim || ln -s $(shell pwd)/nvim $(HOME)/.config/nvim

.PHONY: vscode
vscode:
     test -L $(HOME)/.config/Code/User || ln -s $(shell pwd)/vscode/ $(HOME)/.config/Code/User
     -code --install-extension charliermarsh.ruff
     -code --install-extension eamodio.gitlens
     -code --install-extension github.github-vscode-theme
     -code --install-extension ms-python.python
     -code --install-extension pkief.material-icon-theme
     -code --install-extension tamasfe.even-better-toml
bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi
bashrc

if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi

if ! [[ "$PATH" =~ "$HOME/.local/bin:$HOME/bin:" ]]
then
    PATH="$HOME/.local/bin:$HOME/bin:$PATH"
fi
export PATH

if [ -d ~/.bashrc.d ]; then
        for rc in ~/.bashrc.d/*; do
                if [ -f "$rc" ]; then
                        . "$rc"
                fi
        done
fi

unset rc
gitconfig

[user]
name  = Alex Carney
email = alcarneyme@gmail.com

[alias]
co = checkout
amend = commit --amend --no-edit  # Squash changes into the previous commit

hist = log --branches --remotes --tags --graph --oneline --decorate

s = !git status -sb && git --no-pager diff --shortstat

[credential "https://github.com"]
helper =
helper = !gh auth git-credential

[diff]
algorithm = histogram
colorMoved = default

[merge]
conflictstyle = diff3

[rebase]
autosquash = true
autostash = true

[commit]
verbose = true

[core]
editor = nvim

[pull]
rebase = true

[rerere]
enabled = true

[github]
user = alcarney
starship.toml

"$schema" = 'https://starship.rs/config-schema.json'

add_newline = true

[custom.jj]
ignore_timeout = true
description = "The current jj status"
when = "jj root --ignore-working-copy"
symbol = "jj "
command = '''
jj log --revisions @ --no-graph --ignore-working-copy --color always --limit 1 --template '
  separate(" ",
    change_id.shortest(8),
    bookmarks,
    "|",
    concat(
      if(conflict, "✘"),
      if(divergent, "ξœ₯"),
      if(hidden, ""),
      if(immutable, "β—†"),
    ),
    raw_escape_sequence("\x1b[1;32m") ++ if(empty, "(empty)") ++ raw_escape_sequence("\x1b[0m"),
    raw_escape_sequence("\x1b[1;32m") ++ coalesce(
      truncate_end(29, description.first_line(), "…"),
      "(no description set)",
    ) ++ raw_escape_sequence("\x1b[0m"),
  )
'
'''

[git_state]
disabled = true

[git_commit]
disabled = true

[git_metrics]
disabled = true

[git_branch]
disabled = true

[custom.git_branch]
when = true
command = "jj root --ignore-working-copy >/dev/null 2>&1 || starship module git_branch"