Skip to content

Commit

Permalink
Add delink
Browse files Browse the repository at this point in the history
  • Loading branch information
za3k committed Jan 16, 2016
1 parent 995d449 commit d33aee9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ decolorize
---
Strips ANSI color codes out of a stream

delink
---
Usage: `delink FILE`. Removes a level of symlink, moving the symlink's target in place of the symlink. Can have bad side-effects, use with caution.

dzen-clock
---
Make a small clock at the bottom of the screen
Expand Down
19 changes: 19 additions & 0 deletions delink
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash
# Removes one layer of symlink, preserving the names of the symlink

while [ $# -gt 0 ]; do
if [ -L "$1" ]; then
link="$1"
dir="$(dirname "$1")"
target="$(readlink -f "$link")"
if [ -e "$target" ]
then
cp -P -a --remove-destination "$target" "$link"
else
echo "$1 does not point to a file which exists, skipping" >/dev/stderr
fi
else
echo "$1 is not a symlink, skipping" >/dev/stderr
fi
shift
done

0 comments on commit d33aee9

Please sign in to comment.