update: Added code stats, starship.rs, nvim python and more

Signed-off-by: Sagi Dayan <sagidayan@gmail.com>
This commit is contained in:
Sagi Dayan 2024-10-13 12:08:30 +03:00
parent edd5966d43
commit 74cda27d38
Signed by: sagi
GPG key ID: FAB96BFC63B46458
8 changed files with 262 additions and 1 deletions

1
.gitignore vendored
View file

@ -1 +1,2 @@
report.xml
files/dotfiles/nvim/plugin/

View file

@ -3,7 +3,7 @@ import = [
]
[window]
#opacity = 0.7
#opacity = 0.9
dynamic_padding = true
decorations = "none"

View file

@ -51,6 +51,7 @@ local dapui_ok, dapui = pcall(require, "dapui")
local dap_virt_txt_ok, dap_virt_txt = pcall(require, "nvim-dap-virtual-text")
local mason_dap_ok, mason_dap = pcall(require, "mason-nvim-dap")
local dapgo_ok, dapgo = pcall(require, "dap-go")
local dap_python_ok, dap_python = pcall(require, "dap-python")
if dapui_ok then
dapui.setup()
end
@ -70,6 +71,9 @@ end
if dapgo_ok then
dapgo.setup()
end
if dap_python_ok then
dap_python.setup("python")
end
-- end debugger
--
@ -88,3 +92,21 @@ if harpoon_ok then
}
})
end
local codestats_ok, codestats = pcall(require, "codestats")
if codestats_ok then
local key = os.getenv("CODESTATS_API_KEY") or ""
if key ~= "" then
codestats.setup {
username = 'goomba', -- needed to fetch profile data
base_url = 'https://codestats.net', -- codestats.net base url
api_key = key,
send_on_exit = true, -- send xp on nvim exit
send_on_timer = true, -- send xp on timer
timer_interval = 60000, -- timer interval in milliseconds (minimum 1000ms to prevent DDoSing codestat.net servers)
curl_timeout = 5, -- curl request timeout in seconds
}
else
print("Missing codestats API key... If you want to use CodeStats. Please set CODESTATS_API_KEY env var")
end
end

View file

@ -1,8 +1,20 @@
local servers = {
"pyright",
"jsonls",
"ruff",
}
-- Python virtual environments
local is_vitrual_env = os.getenv("VIRTUAL_ENV") or '' ~= ''
if is_vitrual_env then
print("Running in python venv")
vim.g.python3_host_prog = '/venv/bin/python'
vim.g.python_host_prog = '/venv/bin/python'
end
--
local settings = {
ui = {
icons = {

View file

@ -22,6 +22,7 @@ return require("packer").startup(function(use)
'simrat39/symbols-outline.nvim',
'L3MON4D3/LuaSnip',
'saadparwaiz1/cmp_luasnip',
'nvimtools/none-ls.nvim',
}
-- Debugger
@ -29,6 +30,7 @@ return require("packer").startup(function(use)
use 'theHamsta/nvim-dap-virtual-text'
use "jay-babu/mason-nvim-dap.nvim"
use 'leoluz/nvim-dap-go'
use 'mfussenegger/nvim-dap-python'
-- file tree
use {
@ -92,4 +94,10 @@ return require("packer").startup(function(use)
-- Catppuccin
use { "catppuccin/nvim", as = "catppuccin" }
-- Code Stats
use {
'liljaylj/codestats.nvim',
requires = { { "nvim-lua/plenary.nvim" } }
}
end)

View file

@ -0,0 +1,205 @@
# https://gitlab.com/code-stats/code-stats-zsh
_codestats_version="0.3.11"
zmodload zsh/datetime
declare -g -i _codestats_xp=0
declare -g -i _codestats_pulse_time=${EPOCHSECONDS}
# Because each `curl` call is forked into a subshell to keep the interactive
# shell responsive, the consecutive error count cannot be updated in a
# variable. So we use a temp file, one error per line.
_codestats_consecutive_errors=$(mktemp)
# Logging: write to file if CODESTATS_LOG_FILE is set and exists
_codestats_log()
{
if [[ -w "${CODESTATS_LOG_FILE}" ]]; then
# EPOCHSECONDS is an integer, so disable globbing/splitting warning
# shellcheck disable=SC2086
echo "$(\strftime %Y-%m-%dT%H:%M:%S ${EPOCHSECONDS}) ($$) $*" >> "${CODESTATS_LOG_FILE}"
fi
}
# Widget wrapper: add a keypress and call original widget
_codestats_call_widget()
{
# Bracketed-paste-magic calls self-insert when pasting and sets $PASTED.
# Don't add xp for pasting.
# shellcheck disable=SC2004
if (( ! ${+PASTED} )); then
_codestats_xp+=15
fi
builtin zle "$@"
}
# Rebind widgets
_codestats_rebind_widgets()
{
local w
for w in \
self-insert \
delete-char \
backward-delete-char \
accept-line
do
# call the internal version, ie. the one beginning with `.`
eval "_codestats_${w} () { _codestats_call_widget .${w} -- \"\$@\" }"
zle -N ${w} _codestats_${w}
_codestats_log "Wrapped and rebound the ${w} widget."
done
}
# Pulse sending function
_codestats_send_pulse()
{
# Check that error count hasn't been exceeded
local -i error_count=0
if [[ -r "${_codestats_consecutive_errors}" ]]; then
error_count=$(wc -l < "${_codestats_consecutive_errors}")
fi
if (( error_count > 4 )); then
_codestats_log "Received too many consecutive errors! Stopping..."
_codestats_stop "Received ${error_count} consecutive errors when trying to save XP."
return
fi
# If there's accumulated XP, send it
if (( _codestats_xp > 0 )); then
local url
url="$(_codestats_pulse_url)"
_codestats_log "Sending pulse (${_codestats_xp} xp) to ${url}"
local payload
payload=$(_codestats_payload ${_codestats_xp})
\curl \
--max-time 5 \
--header "Content-Type: application/json" \
--header "X-API-Token: ${CODESTATS_API_KEY}" \
--user-agent "code-stats-zsh/${_codestats_version}" \
--data "${payload}" \
--request POST \
--silent \
--output /dev/null \
--write-out "%{http_code}" \
"${url}" \
| _codestats_handle_response_status \
&|
_codestats_xp=0
fi
}
# Error handling based on HTTP status
_codestats_handle_response_status()
{
local _status
_status=$(\cat -)
case ${_status} in
000)
_codestats_log "Network error!"
# don't stop; maybe the network will start working eventually
;;
200 | 201 )
_codestats_log "Success (${_status})!"
# clear error count
echo -n >! "${_codestats_consecutive_errors}"
;;
3* )
_codestats_log "Unexpected redirect ${_status}!"
_codestats_stop "Server responded with a redirect. Perhaps code-stats-zsh is out of date?"
# this problem will probably not go away. stop immediately.
;;
4* | 5* )
_codestats_log "Server responded with error ${_status}!"
# some of 4xx and 5xx statuses may indicate a temporary problem
echo "${_status}" >>! "${_codestats_consecutive_errors}"
;;
*)
_codestats_log "Unexpected response status ${_status}!"
# whatever happened, stop if it persists
echo "${_status}" >>! "${_codestats_consecutive_errors}"
;;
esac
}
_codestats_pulse_url()
{
echo "${CODESTATS_API_URL:-https://codestats.net}/api/my/pulses"
}
# Create API payload
_codestats_payload()
{
# shellcheck disable=SC2086
cat <<EOF
{
"coded_at": "$(\strftime %Y-%m-%dT%H:%M:%S%z ${EPOCHSECONDS})",
"xps": [{"language": "Terminal (Zsh)", "xp": $1}]
}
EOF
}
# Check time since last pulse; maybe send pulse
_codestats_poll()
{
if (( EPOCHSECONDS - _codestats_pulse_time > 10 )); then
_codestats_send_pulse
_codestats_pulse_time=${EPOCHSECONDS}
fi
}
_codestats_exit()
{
_codestats_log "Shell is exiting. Calling _codestats_send_pulse one last time."
_codestats_send_pulse
# remove temp file
rm -f "${_codestats_consecutive_errors}"
}
_codestats_init()
{
_codestats_log "Initializing code-stats-zsh@${_codestats_version}..."
_codestats_rebind_widgets
# Call the polling function on each new prompt
autoload -U add-zsh-hook
add-zsh-hook precmd _codestats_poll
# Send pulse on shell exit
add-zsh-hook zshexit _codestats_exit
_codestats_log "Initialization complete."
}
# Stop because there was an error. Overwrite handler functions.
_codestats_stop()
{
_codestats_log "Stopping zsh-code-stats. Overwriting hook functions with no-ops."
>&2 echo "code-stats-zsh: $* Stopping."
_codestats_poll() { true; }
_codestats_exit() { true; }
# remove temp file
rm -f "${_codestats_consecutive_errors}"
}
if [[ -n "${CODESTATS_API_KEY}" ]]; then
_codestats_init
else
echo "code-stats-zsh requires CODESTATS_API_KEY to be set!"
false
fi
if [[ -n "${CODESTATS_LOG_FILE}" && ! -w "${CODESTATS_LOG_FILE}" ]]; then
echo "Warning: CODESTATS_LOG_FILE needs to exist and be writable!"
fi

View file

@ -108,6 +108,10 @@ source ~/.shellconfig/aliases.sh
source ~/.shellconfig/environment.sh
# Functions
source ~/.shellconfig/functions.sh
# Codestats if env var is set
if [ -n "$1" ]; then
source ~/.shellconfig/codestats.plugin.zsh
fi
# Auto complete functions
if [ -d ~/.shellconfig/autocomplete ]; then
[ "$(ls -A ~/.shellconfig/autocomplete/)" ] && source <(cat ~/.shellconfig/autocomplete/*)
@ -120,3 +124,5 @@ fi
if [[ $DEVICE_ROLE == "WORKSTATION" ]]; then
[ -z $TMUX ] && (tmux new-session ~/.shellconfig/workspaces/open_workspace.sh)
fi
eval "$(starship init zsh)"

View file

@ -1,3 +1,9 @@
- name: Enable copr for starship.rs
become: true
community.general.copr:
state: enabled
name: atim/starship
- name: Installing packages
become: true
package:
@ -23,6 +29,7 @@
- bat
- fzf
- unzip
- starship
state: present
- name: Copy gitconfig base