Skip to content
This repository has been archived by the owner on Sep 26, 2024. It is now read-only.

If possible, avoid using hash as it hashes binary's path #22

Closed
3 of 14 tasks
CodesOfRishi opened this issue Jan 14, 2022 · 3 comments
Closed
3 of 14 tasks

If possible, avoid using hash as it hashes binary's path #22

CodesOfRishi opened this issue Jan 14, 2022 · 3 comments
Labels
bug Something isn't working enhancement New feature or request

Comments

@CodesOfRishi
Copy link
Owner

CodesOfRishi commented Jan 14, 2022

Are you using the latest version?
v4.0.0

The issue is with the following feature(s):

  • Traversal to root of a git repository.
  • Search & traverse w.r.t. to a base directory.
  • Search & traverse recently visited directories.
  • Sub-directory search & traversal.
  • Parent-directory search & traversal.
  • Piping.
  • Cleaning of log file.
  • Installation.
  • Dependencies/Requirements.
  • Configurations.
  • Documentation.
  • Other(s)

Issue observed in the following shell(s):

  • Bash
  • Zsh

Describe the bug
SmartCd is using hash command to validate whether an executable exist or not.
hash command hashes the searched path for faster lookup next time when it's used again. Hashing is really not necessary here.

Additional context
Possible alternatives:

  • whence command in zsh. (run man zshbuiltins & search whence)
  • type command in bash. (run help type)

Possible solution:

path_search() {
	local _executable=$1
	if ps -p $$ | grep -i --quiet 'zsh$'; then
		whence -p "${_executable}" &> /dev/null
	elif ps -p $$ | grep -i --quiet 'bash$'; then
		type -P "${_executable}" &> /dev/null
	else 
		printf '%s\n' "Shell doesn't seems to be either Base or Zsh" 1>&2
		return 1
	fi
}
@CodesOfRishi CodesOfRishi added bug Something isn't working enhancement New feature or request labels Jan 14, 2022
@CodesOfRishi CodesOfRishi changed the title [BUG] [FEAT] If possible, avoid using hash as it hashes binary's path If possible, avoid using hash as it hashes binary's path Jan 14, 2022
@HaleTom
Copy link

HaleTom commented Jan 14, 2022

Why do you fork two processes (ps and grep) when you could look up (e.g.) $BASH_VERSION or $SHELL ?

@CodesOfRishi
Copy link
Owner Author

Coz for now I'm not sure if it's reliable! Or is it??

@CodesOfRishi
Copy link
Owner Author

CodesOfRishi commented Jan 14, 2022

For example, if you launch another shell as a subprocess, the value of $SHELL won't change!
I am not sure with the other one ($BASH_VERSION)!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants