Skip to content

Instantly share code, notes, and snippets.

@Osse
Created September 28, 2014 19:50
Show Gist options
  • Save Osse/796fd6d84aef904d027c to your computer and use it in GitHub Desktop.
Save Osse/796fd6d84aef904d027c to your computer and use it in GitHub Desktop.
relpath() {
local -a components cur_components rel_path
local i
components=( ${(s:/:)1:a} )
cur_components=( ${(s:/:)PWD:a} )
while [[ $components[1] = $cur_components[1] ]]; do
shift components cur_components
done
for (( i = 0; i <= $#cur_components; i++ )); do
rel_path+=( .. )
done
shift rel_path
rel_path+=( $components )
REPLY=${(j:/:)rel_path}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment