diff --git a/.config/helix/config.toml b/.config/helix/config.toml index a26ff806..0171284e 100644 --- a/.config/helix/config.toml +++ b/.config/helix/config.toml @@ -88,7 +88,6 @@ C-f = "jump_forward" # a = "append_mode_same_line" tab = "trim_selections" C-k = "signature_help" -C-g = [":new", ":insert-output lazygit", ":buffer-close!", ":redraw"] "\\" = ":format" "+" = ":reflow" ret = "goto_word" @@ -132,6 +131,14 @@ A-l = "move_prev_sub_word_start" C-d = ["page_cursor_half_down", "align_view_center"] C-u = ["page_cursor_half_up", "align_view_center"] +# git stuff +[keys.normal.space.g] +# blame +b = ":sh git -C $(dirname $(realpath %{buffer_name})) blame -L %{cursor_line},%{cursor_line} $(realpath %{buffer_name})" +# lazygit +g = [":new", ":insert-output lazygit", ":buffer-close!", ":redraw"] +o = ":sh ~/.config/helix/scripts/get_git_provider_url.fish %{buffer_name} %{cursor_line} | wl-copy" + [keys.normal."["] x = "extend_line_above" [keys.normal.space] diff --git a/.config/helix/scripts/get_git_provider_url.fish b/.config/helix/scripts/get_git_provider_url.fish new file mode 100755 index 00000000..d933b90c --- /dev/null +++ b/.config/helix/scripts/get_git_provider_url.fish @@ -0,0 +1,46 @@ +#!/usr/bin/env fish + +function get_git_provider_url --argument filename line_number + # Check if inside a git repository + if not git rev-parse --is-inside-work-tree >/dev/null 2>&1 + echo "Error: Not inside a git repository." + return 1 + end + + # Get the remote URL + set remote_url (git config --get remote.origin.url) + if test -z "$remote_url" + echo "Error: No remote origin found." + return 1 + end + + # Determine the provider (GitHub, GitLab, etc.) + if string match -q '*github.com*' $remote_url + set provider github + else if string match -q '*gitlab.com*' $remote_url + set provider gitlab + else + echo "Error: Unsupported git provider." + return 1 + end + + # Extract the repo path and branch + set repo_path (echo $remote_url | perl -nE 'say $2 if /\.com(:|\/)(.*)\.git/') + set branch (git rev-parse --abbrev-ref HEAD) + + # Generate the URL based on the provider + switch $provider + case github + echo "https://github.com/$repo_path/blob/$branch/$filename#L$line_number" + case gitlab + echo "https://gitlab.com/$repo_path/-/blob/$branch/$filename#L$line_number" + end +end + +# Ensure correct number of arguments +if [ (count $argv) -ne 2 ] + echo "Usage: script.fish " + return 1 +end + +get_git_provider_url $argv[1] $argv[2] diff --git a/.config/yazi/plugins/custom-shell.yazi/yazi_cmd_history b/.config/yazi/plugins/custom-shell.yazi/yazi_cmd_history index baeadec6..ac30fa0b 100644 --- a/.config/yazi/plugins/custom-shell.yazi/yazi_cmd_history +++ b/.config/yazi/plugins/custom-shell.yazi/yazi_cmd_history @@ -1 +1,2 @@ zsh -ic 'lg;exit' +zsh -ic 'chmod +x get_git_provider_url.fish;exit'