11#! /bin/bash
22
3- alias python=' python3'
4- alias pip=' pip3'
3+ # Only apply for interactive shells. Aliases, functions, prompt hooks, and
4+ # atuin/starship don't make sense in non-interactive bash.
5+ [[ $- == * i* ]] || return
56
6- # if [ "$(uname)" == "Darwin" ]; then
7- # alias gcc='gcc-7'
8- # alias cc='gcc-7'
9- # alias g++='g++-7'
10- # alias c++='g++-7'
11- # fi
7+ # -------------- History Configuration --------------
8+ export HISTCONTROL=erasedups
9+ export HISTSIZE=10000
10+ export HISTFILESIZE=20000
11+ export HISTIGNORE=" ls:ll:cd:pwd:exit:clear:history"
1212
13- if [[ -d ~ /.linuxbrew ]]; then
14- eval " $( /home/pwl45/.linuxbrew/bin/brew shellenv) "
15- fi
13+ alias python=' python3'
14+ alias pip=' pip3'
1615
1716alias duck=' { du -ha | sort -rh | head -20;} 2> /dev/null'
1817
@@ -28,10 +27,11 @@ function brew() {
2827
2928 # Only check deps if we actually removed something successfully
3029 if [[ $? -eq 0 && -n " $pkg " ]]; then
31- local deps=$( join <( brew leaves) <( brew deps " $pkg " ) 2> /dev/null)
32- if [[ -n " $deps " ]]; then
33- echo " Removing unused dependencies: $deps "
34- command brew rm $deps
30+ local -a deps
31+ mapfile -t deps < <( join <( brew leaves) <( brew deps " $pkg " ) 2> /dev/null)
32+ if (( ${# deps[@]} > 0 )) ; then
33+ echo " Removing unused dependencies: ${deps[*]} "
34+ command brew rm " ${deps[@]} "
3535 fi
3636 fi
3737 else
@@ -51,7 +51,14 @@ function git() {
5151}
5252
5353function ls() {
54- if [[ $* == * l* ]]; then
54+ local arg long=0
55+ for arg in " $@ " ; do
56+ if [[ $arg == -[! -]* l* ]]; then
57+ long=1
58+ break
59+ fi
60+ done
61+ if (( long )) ; then
5562 if [[ " $( uname) " == " Darwin" ]]; then
5663 command ls -GhLa " $@ "
5764 else
@@ -62,21 +69,15 @@ function ls() {
6269 fi
6370}
6471
65- function cd() {
66- command cd -P " $@ " || return
67-
68- # Auto-activate venv if present
69- if [[ -d venv ]]; then
70- source venv/bin/activate
71- fi
72-
73- # Always ls after successful cd (the $? check is redundant here)
74- ls -l
75- }
76-
7772function rm() {
78- if [[ $* == * r* ]]
79- then
73+ local arg recursive=0
74+ for arg in " $@ " ; do
75+ if [[ $arg == -[! -]* r* || $arg == -[! -]* R* || $arg == --recursive ]]; then
76+ recursive=1
77+ break
78+ fi
79+ done
80+ if (( recursive )) ; then
8081 command rm -f " $@ "
8182 else
8283 command rm " $@ "
@@ -91,11 +92,7 @@ function rm() {
9192}
9293
9394function cat() {
94- if [[ $* == * .md* ]]; then
95- command mdcat " $@ " 2> /dev/null || command cat " $@ "
96- else
97- command ccat " $@ " 2> /dev/null || command cat " $@ "
98- fi
95+ command bat --style=plain --paging=never " $@ " 2> /dev/null || command cat " $@ "
9996}
10097
10198function extract() {
@@ -125,54 +122,7 @@ function gh() {
125122 local exit_code=$?
126123
127124 if [[ $exit_code -eq 0 ]]; then
128- # Find the repo argument (first non-flag, non-subcommand arg)
129- local repo_arg=" "
130- for arg in " ${@: 3} " ; do
131- if [[ " $arg " != -* ]]; then
132- repo_arg=" $arg "
133- break
134- fi
135- done
136-
137- if [[ -n " $repo_arg " ]]; then
138- local repo_name=$( basename " $repo_arg " .git)
139- if [[ -d " $repo_name " ]]; then
140- (
141- cd " $repo_name " || exit 1
142- # Get the repository from the origin remote and set it explicitly
143- local origin_url=$( git remote get-url origin 2> /dev/null)
144- if [[ -n " $origin_url " ]]; then
145- # Extract owner/repo from the URL
146- local repo_path=" "
147- case " $origin_url " in
148- * github.com* )
149- repo_path=$( echo " $origin_url " | sed -E ' s|.*github\.com[:/]([^/]+/[^/]+)(\.git)?.*|\1|' )
150- ;;
151- esac
152-
153- if [[ -n " $repo_path " ]]; then
154- command gh repo set-default " $repo_path " 2> /dev/null || true
155- else
156- command gh repo set-default 2> /dev/null || true
157- fi
158- fi
159- )
160- fi
161- fi
162- fi
163-
164- return $exit_code
165- else
166- command gh " $@ "
167- fi
168- }
169-
170- function gh() {
171- if [[ " $1 " == " repo" && " $2 " == " clone" ]]; then
172- command gh " $@ "
173- local exit_code=$?
174-
175- if [[ $exit_code -eq 0 ]]; then
125+ # First non-flag arg after "clone" is the repo identifier
176126 local repo_arg=" "
177127 for arg in " ${@: 3} " ; do
178128 if [[ " $arg " != -* ]]; then
@@ -182,10 +132,18 @@ function gh() {
182132 done
183133
184134 if [[ -n " $repo_arg " ]]; then
185- local repo_name=$( basename " $repo_arg " .git)
186- if [[ -d " $repo_name " ]]; then
187- cd " $repo_name " || return 1
188- command gh repo set-default " $repo_arg " 2> /dev/null || true
135+ local repo_name
136+ repo_name=$( basename " $repo_arg " .git)
137+ if [[ -d " $repo_name " ]] && cd " $repo_name " ; then
138+ # Derive owner/repo from origin so set-default works regardless
139+ # of which form the user passed to clone (owner/repo, https://, git@…)
140+ local origin_url
141+ origin_url=$( git remote get-url origin 2> /dev/null)
142+ if [[ " $origin_url " == * github.com* ]]; then
143+ local repo_path
144+ repo_path=$( echo " $origin_url " | sed -E ' s|.*github\.com[:/]([^/]+/[^/]+)(\.git)?.*|\1|' )
145+ [[ -n " $repo_path " ]] && command gh repo set-default " $repo_path " 2> /dev/null || true
146+ fi
189147 fi
190148 fi
191149 fi
@@ -196,6 +154,8 @@ function gh() {
196154 fi
197155}
198156
199- # # Need something like this for atuin
200- source ~ /.bash-preexec.sh
201- eval " $( atuin init bash) "
157+ # -------------- Per-shell tool initialization --------------
158+ # These hook into PROMPT_COMMAND / keybindings / PS1, which are shell-local —
159+ # they must run in every interactive shell, not just login shells. Hence .bashrc.
160+ [ -x " $( command -v starship) " ] && eval " $( starship init bash) "
161+ [ -x " $( command -v atuin) " ] && eval " $( atuin init bash) "
0 commit comments