0

The problem: Edit many files in one single kate process.

  1. FILE_LIST is a variable which contains a list of path

    FILE_LIST="$MAIN_PATH1  $MAIN_PATH2 ... $MAIN_PATH3"
    
  2. DST_DIR is the destination folder in /tmp for the symlink of the files to edit.

  3. A for - loop feed a find request

  4. The find request uses xargs to build the link files; one uses print0/-0 because some filename contains space

    for A_DIR in $LIST_PATH ; do
    
        find "$A_DIR" -type f  ! -name "*.*~" ! -path "*000_ERRORS*" ! -path "*KEEP*" -print0 | xargs -0 -I@  bash -c " ln -s \"@\"  \"$DST_DIR/${@##*/}\""
    
    done
    
  5. Up to here everything is alright. All symlinks are in one folder.

  6. Then another finds request feed kate at once.

    find "$WORK_PATH" -type l -print0 | xargs -0 -I{} xdg-su -c "kate {} "

That does not work as expected. Files are only accessible one by one. That is not the goal.

But in another terminal if I run manually second find request command :

find /tmp/000_PGM_001 -type l -print0 | xargs -L 1 -0 -I{} bash -c "kate '{}'"

I may obtain all the files in the same instance. I may manually repeat the command until I get all the files in one kate install.

1 Answer 1

0

Sounds like you need (assuming a GNU system)

dirs=(
  "$MAIN_PATH1"
  "$MAIN_PATH2"
  "$MAIN_PATH3"
)
LC_ALL=C find "${dirs[@]}" -name '*000_ERRORS*' -prune -o \
  '*KEEP*' -prune -o ! -name '*~' -type f -exec ln -st "$DST_DIR" {} +

And for your kate thing:

find "$WORK_PATH" -type l -exec env LINK='{}' xdg-su -c 'kate "$LINK"' ';'

Here passing the file path as an environment variable and assuming xdg-su or the command that script runs in your desktop environment doesn't strip it.

In any case, looking at the contents of that xdg-su script, you'd want to pass it only fixed commands to run like that kate "$LINK"; passing it arbitrary data would be unreliable and dangerous.

1
  • OK, I have a try
    – jcdole
    Commented Feb 3 at 17:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .