Skip to content

Commit

Permalink
Handle repos with no remotes set
Browse files Browse the repository at this point in the history
  • Loading branch information
j4ckofalltrades committed Jan 11, 2024
1 parent 430dfb7 commit eee53fb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 31 deletions.
21 changes: 0 additions & 21 deletions LICENSE

This file was deleted.

24 changes: 14 additions & 10 deletions branch-win-title.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash

# Add the current git branch name to the terminal emulator window title.

#
# MIT License
#
# Copyright (c) 2021 Jordan Duabe
Expand Down Expand Up @@ -33,26 +33,30 @@ fi

# Determine if the current directory is a git repo
__is_git_repo() {
git branch --show-current > /dev/null 2>&1
$(git branch --show-current > /dev/null 2>&1)
echo "$?"
}

# Build window tite that includes the name of the current branch; defaults to
# `user@host:current_working_directory` if current directory is not a git repo.
__branch_win_title() {
if [ "$(__is_git_repo)" -eq 0 ]; then
local curr_dir
local curr_branch
if [[ "$(__is_git_repo)" -eq 0 ]]; then
local branch
local dir

curr_dir="$(basename -s .git "$(git remote get-url origin)")"
curr_branch="$(git branch --show-current)"
if [[ -n "$(git remote show)" ]]; then
dir="$(basename -s .git "$(git remote get-url origin)")"
else
dir="${PWD/*\//}"
fi

if [ -n "$curr_branch" ]; then
echo "${curr_dir} - [${curr_branch}]"
branch="$(git branch --show-current)"
if [[ -n "$branch" ]]; then
echo "${dir} - [${branch}]"
else
local detached_commit
detached_commit="$(git show -s --format=%h)"
echo "${curr_dir} - [detached at ${detached_commit}]"
echo "${dir} - [detached at ${detached_commit}]"
fi
else
case "${CURR_SHELL}" in
Expand Down

0 comments on commit eee53fb

Please sign in to comment.